Skip to content

Commit

Permalink
Remove graphhopper dependency (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored Mar 1, 2022
1 parent 1f75ad2 commit 8a6997f
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 116 deletions.
2 changes: 2 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The `planetiler-core` module includes the following software:
- org.xerial:sqlite-jdbc (Apache license)
- com.ibm.icu:icu4j ([ICU license](https://github.com/unicode-org/icu/blob/main/icu4c/LICENSE))
- com.google.guava:guava (Apache license)
- org.openstreetmap.osmosis:osmosis-osm-binary (LGPL 3.0)
- com.carrotsearch:hppc (Apache license)
- Adapted code:
- `DouglasPeuckerSimplifier` from [JTS](https://github.com/locationtech/jts) (EDL)
- `OsmMultipolygon` from [imposm3](https://github.com/omniscale/imposm3) (Apache license)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Planetiler is made possible by these awesome open source projects:
and [reference implementation](https://github.com/openmaptiles/openmaptiles)
that the [basemap profile](planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/layers)
is based on
- [Graphhopper](https://www.graphhopper.com/) for utilities to process OpenStreetMap data in Java
- [Graphhopper](https://www.graphhopper.com/) for basis of utilities to process OpenStreetMap data in Java
- [JTS Topology Suite](https://github.com/locationtech/jts) for working with vector geometries
- [Geotools](https://github.com/geotools/geotools) for shapefile processing
- [SQLite JDBC Driver](https://github.com/xerial/sqlite-jdbc) for reading Natural Earth data and writing MBTiles files
Expand All @@ -239,6 +239,8 @@ Planetiler is made possible by these awesome open source projects:
- [imposm3](https://github.com/omniscale/imposm3) for the basis
of [OSM multipolygon processing](planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/OsmMultipolygon.java)
and [tag parsing utilities](planetiler-core/src/main/java/com/onthegomap/planetiler/util/Imposm3Parsers.java)
- [HPPC](http://labs.carrotsearch.com/) for high-performance primitive Java collections
- [Osmosis](https://wiki.openstreetmap.org/wiki/Osmosis) for Java utilities to parse OpenStreetMap data

See [NOTICE.md](NOTICE.md) for a full list and license details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static java.util.stream.Collectors.groupingBy;

import com.carrotsearch.hppc.LongObjectMap;
import com.graphhopper.coll.GHLongObjectHashMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.basemap.BasemapProfile;
import com.onthegomap.planetiler.basemap.generated.OpenMapTilesSchema;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
Expand Down Expand Up @@ -390,7 +390,7 @@ private BorderingRegions getBorderingRegions(
/** Returns a map from region ID to prepared geometry optimized for {@code contains} queries. */
private LongObjectMap<PreparedGeometry> prepareRegionPolygons() {
LOGGER.info("Creating polygons for " + regionGeometries.size() + " boundaries");
LongObjectMap<PreparedGeometry> countryBoundaries = new GHLongObjectHashMap<>();
LongObjectMap<PreparedGeometry> countryBoundaries = Hppc.newLongObjectHashMap();
for (var entry : regionGeometries.entrySet()) {
Long regionId = entry.getKey();
Polygonizer polygonizer = new Polygonizer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static com.onthegomap.planetiler.basemap.util.Utils.elevationTags;
import static com.onthegomap.planetiler.basemap.util.Utils.nullIfEmpty;

import com.carrotsearch.hppc.LongIntHashMap;
import com.carrotsearch.hppc.LongIntMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.basemap.BasemapProfile;
import com.onthegomap.planetiler.basemap.generated.OpenMapTilesSchema;
import com.onthegomap.planetiler.basemap.generated.Tables;
import com.onthegomap.planetiler.basemap.util.LanguageUtils;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.reader.SourceFeature;
Expand Down Expand Up @@ -171,7 +171,7 @@ private boolean peakInAreaUsingFeet(Tables.OsmPeakPoint element) {

@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
LongIntMap groupCounts = new LongIntHashMap();
LongIntMap groupCounts = Hppc.newLongIntHashMap();
for (int i = 0; i < items.size(); i++) {
VectorTile.Feature feature = items.get(i);
int gridrank = groupCounts.getOrDefault(feature.group(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static com.onthegomap.planetiler.basemap.util.Utils.nullIfEmpty;
import static com.onthegomap.planetiler.collection.FeatureGroup.SORT_KEY_BITS;

import com.carrotsearch.hppc.LongIntHashMap;
import com.carrotsearch.hppc.LongIntMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
Expand All @@ -48,6 +47,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.onthegomap.planetiler.basemap.generated.OpenMapTilesSchema;
import com.onthegomap.planetiler.basemap.generated.Tables;
import com.onthegomap.planetiler.basemap.util.LanguageUtils;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
Expand Down Expand Up @@ -145,7 +145,7 @@ private int getMinZoomForArea(double area) {
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) throws GeometryException {
// infer the "rank" attribute from point ordering within each label grid square
LongIntMap counts = new LongIntHashMap();
LongIntMap counts = Hppc.newLongIntHashMap();
for (VectorTile.Feature feature : items) {
if (feature.geometry().geomType() == GeometryType.POINT && feature.hasGroup()) {
int count = counts.getOrDefault(feature.group(), 0) + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static com.onthegomap.planetiler.basemap.util.Utils.nullOrEmpty;
import static com.onthegomap.planetiler.collection.FeatureGroup.SORT_KEY_BITS;

import com.carrotsearch.hppc.LongIntHashMap;
import com.carrotsearch.hppc.LongIntMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.basemap.BasemapProfile;
import com.onthegomap.planetiler.basemap.generated.OpenMapTilesSchema;
import com.onthegomap.planetiler.basemap.generated.Tables;
import com.onthegomap.planetiler.basemap.util.LanguageUtils;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
Expand Down Expand Up @@ -366,7 +366,7 @@ public void process(Tables.OsmCityPoint element, FeatureCollector features) {
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
// infer the rank field from ordering of the place labels with each label grid square
LongIntMap groupCounts = new LongIntHashMap();
LongIntMap groupCounts = Hppc.newLongIntHashMap();
for (VectorTile.Feature feature : items) {
int gridrank = groupCounts.getOrDefault(feature.group(), 1);
groupCounts.put(feature.group(), gridrank + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static com.onthegomap.planetiler.basemap.util.Utils.nullOrEmpty;
import static java.util.Map.entry;

import com.carrotsearch.hppc.LongIntHashMap;
import com.carrotsearch.hppc.LongIntMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.basemap.BasemapProfile;
import com.onthegomap.planetiler.basemap.generated.OpenMapTilesSchema;
import com.onthegomap.planetiler.basemap.generated.Tables;
import com.onthegomap.planetiler.basemap.util.LanguageUtils;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.expression.MultiExpression;
import com.onthegomap.planetiler.stats.Stats;
Expand Down Expand Up @@ -182,7 +182,7 @@ void setupPoiFeature(T element, FeatureCollector.Feature output) {
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
// infer the "rank" field from the order of features within each label grid square
LongIntMap groupCounts = new LongIntHashMap();
LongIntMap groupCounts = Hppc.newLongIntHashMap();
for (VectorTile.Feature feature : items) {
int gridrank = groupCounts.getOrDefault(feature.group(), 1);
groupCounts.put(feature.group(), gridrank + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static com.onthegomap.planetiler.basemap.util.Utils.*;

import com.carrotsearch.hppc.LongArrayList;
import com.carrotsearch.hppc.LongByteHashMap;
import com.carrotsearch.hppc.LongByteMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
Expand All @@ -51,6 +50,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.onthegomap.planetiler.basemap.generated.OpenMapTilesSchema;
import com.onthegomap.planetiler.basemap.generated.Tables;
import com.onthegomap.planetiler.basemap.util.LanguageUtils;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.reader.osm.OsmElement;
import com.onthegomap.planetiler.stats.Stats;
Expand Down Expand Up @@ -121,7 +121,7 @@ public class TransportationName implements
private final boolean limitMerge;
private final PlanetilerConfig config;
private Transportation transportation;
private final LongByteMap motorwayJunctionHighwayClasses = new LongByteHashMap();
private final LongByteMap motorwayJunctionHighwayClasses = Hppc.newLongByteHashMap();

public TransportationName(Translations translations, PlanetilerConfig config, Stats stats) {
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static com.onthegomap.planetiler.basemap.util.Utils.nullIfEmpty;

import com.carrotsearch.hppc.LongObjectMap;
import com.graphhopper.coll.GHLongObjectHashMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.basemap.BasemapProfile;
import com.onthegomap.planetiler.basemap.generated.OpenMapTilesSchema;
import com.onthegomap.planetiler.basemap.generated.Tables;
import com.onthegomap.planetiler.basemap.util.LanguageUtils;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
Expand Down Expand Up @@ -84,7 +84,7 @@ public class WaterName implements
private static final double LOG2 = Math.log(2);
private final Translations translations;
// need to synchronize updates from multiple threads
private final LongObjectMap<Geometry> lakeCenterlines = new GHLongObjectHashMap<>();
private final LongObjectMap<Geometry> lakeCenterlines = Hppc.newLongObjectHashMap();
// may be updated concurrently by multiple threads
private final ConcurrentSkipListMap<String, Integer> importantMarinePoints = new ConcurrentSkipListMap<>();
private final Stats stats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

import com.carrotsearch.hppc.LongObjectHashMap;
import com.google.common.util.concurrent.AtomicDouble;
import com.graphhopper.coll.GHLongObjectHashMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.VectorTile;
Expand All @@ -48,6 +47,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.onthegomap.planetiler.basemap.generated.Tables;
import com.onthegomap.planetiler.basemap.util.LanguageUtils;
import com.onthegomap.planetiler.basemap.util.Utils;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.reader.SourceFeature;
Expand Down Expand Up @@ -98,7 +98,7 @@ public class Waterway implements
private final Translations translations;
private final PlanetilerConfig config;
private final Stats stats;
private final LongObjectHashMap<AtomicDouble> riverRelationLengths = new GHLongObjectHashMap<>();
private final LongObjectHashMap<AtomicDouble> riverRelationLengths = Hppc.newLongObjectHashMap();

public Waterway(Translations translations, PlanetilerConfig config, Stats stats) {
this.config = config;
Expand Down
12 changes: 8 additions & 4 deletions planetiler-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@
</parent>

<properties>
<graphhopper.version>2.4</graphhopper.version>
<geotools.version>26.3</geotools.version>
<log4j.version>2.17.2</log4j.version>
<prometheus.version>0.15.0</prometheus.version>
</properties>

<dependencies>
<dependency>
<groupId>com.graphhopper</groupId>
<artifactId>graphhopper-reader-osm</artifactId>
<version>${graphhopper.version}</version>
<groupId>com.carrotsearch</groupId>
<artifactId>hppc</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.openstreetmap.osmosis</groupId>
<artifactId>osmosis-osm-binary</artifactId>
<version>0.48.3</version>
</dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.carrotsearch.hppc.IntArrayList;
import com.carrotsearch.hppc.IntObjectMap;
import com.carrotsearch.hppc.IntStack;
import com.graphhopper.coll.GHIntObjectHashMap;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.geo.DouglasPeuckerSimplifier;
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
Expand Down Expand Up @@ -394,7 +394,7 @@ private static IntObjectMap<IntArrayList> extractAdjacencyList(List<Geometry> ge
env.expandBy(minDist);
envelopeIndex.insert(env, i);
}
IntObjectMap<IntArrayList> result = new GHIntObjectHashMap<>();
IntObjectMap<IntArrayList> result = Hppc.newIntObjectHashMap();
for (int _i = 0; _i < geometries.size(); _i++) {
int i = _i;
Geometry a = geometries.get(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.onthegomap.planetiler.collection;

import com.carrotsearch.hppc.LongLongHashMap;
import com.graphhopper.coll.GHLongLongHashMap;
import com.onthegomap.planetiler.Profile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.config.PlanetilerConfig;
Expand Down Expand Up @@ -474,7 +473,7 @@ void add(SortableFeature entry) {
if (extractHasGroupFromKey(key)) {
byte thisLayer = extractLayerIdFromKey(key);
if (counts == null) {
counts = new GHLongLongHashMap();
counts = Hppc.newLongLongHashMap();
layer = thisLayer;
} else if (thisLayer != layer) {
layer = thisLayer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.onthegomap.planetiler.collection;


import com.carrotsearch.hppc.IntObjectHashMap;
import com.carrotsearch.hppc.LongByteHashMap;
import com.carrotsearch.hppc.LongByteMap;
import com.carrotsearch.hppc.LongIntHashMap;
import com.carrotsearch.hppc.LongLongHashMap;
import com.carrotsearch.hppc.LongObjectHashMap;
import com.carrotsearch.hppc.ObjectIntHashMap;

/**
* Static factory method for <a href="https://github.com/carrotsearch/hppc">High Performance Primitive Collections</a>.
*/
public class Hppc {

public static <T> IntObjectHashMap<T> newIntObjectHashMap() {
return new IntObjectHashMap<>(10, 0.75);
}

public static <T> ObjectIntHashMap<T> newObjectIntHashMap() {
return new ObjectIntHashMap<>(10, 0.75);
}

public static LongLongHashMap newLongLongHashMap() {
return new LongLongHashMap(10, 0.75);
}

public static <T> LongObjectHashMap<T> newLongObjectHashMap() {
return new LongObjectHashMap<>(10, 0.75);
}

public static <T> LongObjectHashMap<T> newLongObjectHashMap(int size) {
return new LongObjectHashMap<>(size, 0.75);
}

public static LongIntHashMap newLongIntHashMap() {
return new LongIntHashMap(10, 0.75);
}

public static LongByteMap newLongByteHashMap() {
return new LongByteHashMap(10, 0.75);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import com.carrotsearch.hppc.LongArrayList;
import com.carrotsearch.hppc.LongIntHashMap;
import com.graphhopper.util.StopWatch;
import com.onthegomap.planetiler.stats.Timer;
import com.onthegomap.planetiler.util.MemoryEstimator;
import java.util.Arrays;
import org.slf4j.Logger;
Expand Down Expand Up @@ -81,7 +81,7 @@ private void prepare() {

/** Sort the keys and values arrays by key */
private void doPrepare() {
StopWatch watch = new StopWatch().start();
Timer timer = Timer.start();

LOGGER.debug("Sorting long long multimap...");
long[] sortedKeys = keys.toArray();
Expand Down Expand Up @@ -114,7 +114,7 @@ private void doPrepare() {
}
keys.buffer = sortedKeys;
values.buffer = sortedValues;
LOGGER.debug("Sorted long long multimap " + watch.stop());
LOGGER.debug("Sorted long long multimap " + timer.stop());
}

@Override
Expand Down Expand Up @@ -152,7 +152,7 @@ public long estimateMemoryUsageBytes() {
class DenseOrderedHppcMultimap implements LongLongMultimap {

private static final LongArrayList EMPTY_LIST = new LongArrayList();
private final LongIntHashMap keyToValuesIndex = new LongIntHashMap();
private final LongIntHashMap keyToValuesIndex = Hppc.newLongIntHashMap();
// each block starts with a "length" header then contains that number of entries
private final LongArrayList values = new LongArrayList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import com.carrotsearch.hppc.LongObjectMap;
import com.carrotsearch.hppc.ObjectIntMap;
import com.carrotsearch.hppc.cursors.LongObjectCursor;
import com.graphhopper.coll.GHLongObjectHashMap;
import com.graphhopper.coll.GHObjectIntHashMap;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
import java.util.ArrayList;
Expand Down Expand Up @@ -95,7 +94,7 @@ public boolean isHole() {
* @throws GeometryException if building the polygon fails
*/
public static Geometry build(List<CoordinateSequence> rings) throws GeometryException {
ObjectIntMap<Coordinate> coordToId = new GHObjectIntHashMap<>();
ObjectIntMap<Coordinate> coordToId = Hppc.newObjectIntHashMap();
List<Coordinate> idToCoord = new ArrayList<>();
int id = 0;
List<LongArrayList> idRings = new ArrayList<>(rings.size());
Expand Down Expand Up @@ -314,7 +313,7 @@ static LongArrayList prependToSkipLast(LongArrayList orig, LongArrayList toPrepe
}

static List<LongArrayList> connectPolygonSegments(List<LongArrayList> outer) {
LongObjectMap<LongArrayList> endpointIndex = new GHLongObjectHashMap<>(outer.size() * 2);
LongObjectMap<LongArrayList> endpointIndex = Hppc.newLongObjectHashMap(outer.size() * 2);
List<LongArrayList> completeRings = new ArrayList<>(outer.size());

for (LongArrayList ids : outer) {
Expand Down
Loading

0 comments on commit 8a6997f

Please sign in to comment.