Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declarative schema from configuration file #160

Merged
merged 241 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 234 commits
Commits
Show all changes
241 commits
Select commit Hold shift + click to select a range
b96b40f
Intial water implementation
ZeLonewolf Mar 21, 2022
2884d6d
Merge branch 'onthegomap:main' into owg_schema
ZeLonewolf Mar 21, 2022
53dc7ae
Cleanup
ZeLonewolf Mar 22, 2022
3edb7a4
Merge branch 'owg_schema' of github.com:ZeLonewolf/planetiler into ow…
ZeLonewolf Mar 22, 2022
fa24380
Add waterway
ZeLonewolf Mar 22, 2022
651f53e
Merge branch 'onthegomap:main' into owg_schema
ZeLonewolf Mar 22, 2022
ec168f0
Add size-based name label logic
ZeLonewolf Mar 23, 2022
9549342
Merge branch 'owg_schema' of github.com:ZeLonewolf/planetiler into ow…
ZeLonewolf Mar 23, 2022
8065d74
WIP
ZeLonewolf Mar 26, 2022
4866cb4
Add schema JSON
ZeLonewolf Mar 26, 2022
0515bfd
Add tag includeWhen
ZeLonewolf Mar 26, 2022
4382901
Remove static attribute processor bug
ZeLonewolf Mar 26, 2022
cdf6e77
Add feature size tests for name
ZeLonewolf Mar 26, 2022
de2aa21
Fix exclude function
ZeLonewolf Mar 26, 2022
ebf47e2
Fix exclude functions
ZeLonewolf Mar 26, 2022
f2de0b8
Remove legacy feature description
ZeLonewolf Mar 26, 2022
2038f91
Merge branch 'onthegomap:main' into owg_schema
ZeLonewolf Mar 26, 2022
f5772e8
Add line/point geometry type checks
ZeLonewolf Mar 27, 2022
dfa81ec
Merge branch 'owg_schema' of [email protected]:ZeLonewolf/planetiler.git…
ZeLonewolf Mar 27, 2022
1d051e4
Merge branch 'owg_schema' of [email protected]:ZeLonewolf/planetiler.git
ZeLonewolf Mar 27, 2022
ce52c8c
Add waterway features to water layer
ZeLonewolf Mar 27, 2022
f2fd858
Convert waterway to configured version
ZeLonewolf Mar 27, 2022
5bd7ad5
Make sources configurable
ZeLonewolf Mar 28, 2022
7cb7e65
Remove old code
ZeLonewolf Mar 28, 2022
2d7d082
Add yml version of owg schema
ZeLonewolf Apr 1, 2022
de52fda
Convert to YAML config
ZeLonewolf Apr 2, 2022
9e60a77
Convert from JSON to YAML
ZeLonewolf Apr 2, 2022
2833ec6
Convert configuration language to YAML
ZeLonewolf Apr 4, 2022
2d993bf
Remove debug output
ZeLonewolf Apr 4, 2022
8744252
Merge branch 'onthegomap:main' into owg_schema
ZeLonewolf Apr 4, 2022
e4e34da
Fix bugs in water layer processing
ZeLonewolf Apr 7, 2022
ff1138e
Add motorway linestring test
ZeLonewolf Apr 7, 2022
189c888
Add owg_simple sample
ZeLonewolf Apr 8, 2022
5d7dcb0
Merge branch 'onthegomap:main' into owg_schema
ZeLonewolf Apr 8, 2022
3474a12
Apply spotless
ZeLonewolf Apr 8, 2022
9d00e50
Update entry points
ZeLonewolf Apr 9, 2022
f0c2078
Add documentation
ZeLonewolf Apr 9, 2022
fb3705d
Merge branch 'main' into owg_schema
ZeLonewolf Apr 9, 2022
2a01f10
Merge branch 'onthegomap:main' into owg_schema
ZeLonewolf Apr 9, 2022
c58962b
Ignore mbtiles outputs
ZeLonewolf Apr 9, 2022
3d551f7
Merge branch 'owg_schema' of [email protected]:ZeLonewolf/planetiler.git…
ZeLonewolf Apr 9, 2022
dbab4ff
Add zoom configuration
ZeLonewolf Apr 9, 2022
937e60e
Add tag-based zoom filter
ZeLonewolf Apr 9, 2022
7fe0b47
Add service implementation
ZeLonewolf Apr 9, 2022
562046a
Hook custommap into dist
ZeLonewolf Apr 9, 2022
a58a13b
Spotless
ZeLonewolf Apr 9, 2022
3dde7c8
Add documentation
ZeLonewolf Apr 9, 2022
58da975
Default output to data/ folder
ZeLonewolf Apr 11, 2022
f804da2
Apply spotless
ZeLonewolf Apr 11, 2022
1730f7b
Refactor TagCriteria
ZeLonewolf Apr 11, 2022
b0f3d60
Remove datatype processing
ZeLonewolf Apr 13, 2022
59945bb
Update README.md
ZeLonewolf Apr 14, 2022
274b94e
Spotless
ZeLonewolf Apr 14, 2022
ceeb099
Implement input data typing
ZeLonewolf Apr 16, 2022
b9c89a4
Change source configuration to use geofabrik URLs
ZeLonewolf Apr 17, 2022
2fc74a1
Update unit tests to use new URL scheme
ZeLonewolf Apr 17, 2022
c5162ef
Use simplified Map.of() syntax
ZeLonewolf Apr 17, 2022
48b1c05
Spotless
ZeLonewolf Apr 17, 2022
0641e0a
Simplify loops
ZeLonewolf Apr 17, 2022
7cd1efb
Remove unneeded labelgrid code
ZeLonewolf Apr 17, 2022
d065e1d
Change sources to a map
ZeLonewolf Apr 17, 2022
d110150
Use test functions to make fake objects
ZeLonewolf Apr 17, 2022
97ba5b4
Make constructor-set variables final
ZeLonewolf Apr 17, 2022
fa7fe2f
Refactor arguments processing
ZeLonewolf Apr 17, 2022
f8f0838
Refactor test code
ZeLonewolf Apr 17, 2022
0daac28
Change geometry type to use core class
ZeLonewolf Apr 17, 2022
6ee62df
Improve modeling of data type configuration
ZeLonewolf Apr 17, 2022
3ba11eb
Remove unneeded zoom limits
ZeLonewolf Apr 17, 2022
c1b67bb
Spotless
ZeLonewolf Apr 17, 2022
9e494eb
Convert most configuration schema classes to records
ZeLonewolf Apr 18, 2022
d857cf0
Convert schema to records
ZeLonewolf Apr 18, 2022
896f3cd
Fix lowercase data types
ZeLonewolf Apr 18, 2022
b7c4fd8
Call setAttr instead of setAttrWithMinZoom in some cases
ZeLonewolf Apr 18, 2022
79bd8d0
Fix min/max zoom functionality
ZeLonewolf Apr 18, 2022
65a127c
spotless
ZeLonewolf Apr 18, 2022
d24e91c
Add data typing to Expression
ZeLonewolf Apr 23, 2022
2840980
Keys are always strings
ZeLonewolf Apr 23, 2022
79c53f7
Fix failing test cases due to varargs type conversion
ZeLonewolf Apr 23, 2022
3097d9a
Fix test case method name typo
ZeLonewolf Apr 23, 2022
3c5a4a8
Fix sonar findings / formatting
ZeLonewolf Apr 23, 2022
a65ecc4
Spotless
ZeLonewolf Apr 23, 2022
d5108c9
Merge branch 'main' into expression_object
ZeLonewolf Apr 23, 2022
7278f7d
Run spotless
ZeLonewolf Apr 23, 2022
c2ccd4c
Add temporary hack
ZeLonewolf Apr 23, 2022
7f2bbe3
Remove hack
ZeLonewolf Apr 23, 2022
06530ad
Map getter should be static
ZeLonewolf Apr 23, 2022
37c671b
Spotless
ZeLonewolf Apr 23, 2022
9009d91
Cleanup
ZeLonewolf Apr 23, 2022
ec4d0bd
Fix imports
ZeLonewolf Apr 23, 2022
5880ed3
test commenting out lake/waterway matching
ZeLonewolf Apr 24, 2022
4f3c93f
Fix logic for OMT water layer
ZeLonewolf Apr 24, 2022
1c4ef4a
Remove redundant null check
ZeLonewolf Apr 24, 2022
a42fee8
Merge branch 'expression_object' into owg_schema
ZeLonewolf Apr 24, 2022
e56a129
make matching deterministic
msbarry Apr 25, 2022
0af2e2c
Move string constants to arbitrary getter function
ZeLonewolf Apr 25, 2022
83f0572
Handle no-quoted java primitives in toString()
ZeLonewolf Apr 25, 2022
3aca3e2
Add test case for toString()
ZeLonewolf Apr 25, 2022
eddb202
Spotless
ZeLonewolf Apr 25, 2022
457f49e
Merge branch 'expression_object' into owg_schema
ZeLonewolf Apr 25, 2022
3ff1888
Merge object/expression branch
ZeLonewolf Apr 26, 2022
fb17fa6
Merge branch 'main' into owg_schema
ZeLonewolf Apr 28, 2022
0605284
Remove .gitignore linebreak
ZeLonewolf Apr 28, 2022
4d9693e
Use WIthTags instead of SourceFeature
ZeLonewolf Apr 28, 2022
2a68d8c
Remove unused stringify method
ZeLonewolf Apr 28, 2022
4cbbb21
Merge branch 'main' into owg_schema
ZeLonewolf Apr 29, 2022
fb54820
Merge branch 'onthegomap:main' into owg_schema
ZeLonewolf Apr 30, 2022
dc6a70f
Add failing test cases
ZeLonewolf Apr 30, 2022
2245ad7
Implement configurable schema
ZeLonewolf Apr 30, 2022
514259b
Add missing NOT key checks
ZeLonewolf Apr 30, 2022
d7e275c
Undo unrelated simplify
ZeLonewolf Apr 30, 2022
cedd00a
Merge branch 'owg_schema' of github.com:ZeLonewolf/planetiler into ow…
ZeLonewolf Apr 30, 2022
bd43947
Merge branch 'nor_nand_bug' into owg_schema
ZeLonewolf Apr 30, 2022
f1c1d84
Collapse & simplify code
ZeLonewolf Apr 30, 2022
b2ab8a8
Add and/or constant tests
ZeLonewolf Apr 30, 2022
031964b
Merge branch 'logic_tests' into zelonewolf_logic_tests
msbarry May 1, 2022
e5315b9
More robust multiexpression filtering
msbarry May 1, 2022
663282c
move
msbarry May 1, 2022
8ffa638
Merge remote-tracking branch 'upstream/zelonewolf_logic_tests' into o…
ZeLonewolf May 2, 2022
384f9fe
Convert to streams API
ZeLonewolf May 2, 2022
b476b72
Handle empty criterion case
ZeLonewolf May 2, 2022
1e66d3e
Make test cases pass with dodgy call to simplify()
ZeLonewolf May 2, 2022
8ecaa0a
Remove simplify that's not needed.
ZeLonewolf May 2, 2022
5c25677
Fix evaluate implementation
ZeLonewolf May 2, 2022
83debd9
Cleanup expression new evaluate()
ZeLonewolf May 2, 2022
f82a013
Remove print statement
ZeLonewolf May 2, 2022
466177a
Implement typed expressions
ZeLonewolf May 3, 2022
5266c64
Fix Expression logic
ZeLonewolf May 3, 2022
1299206
Collapse switch statement
ZeLonewolf May 3, 2022
497397d
Remove empty semi-colon
ZeLonewolf May 3, 2022
a5b107b
Cleanup exception declaration
ZeLonewolf May 3, 2022
6942815
Remove reluctant qualifier
ZeLonewolf May 3, 2022
a0baded
Switch to constant
ZeLonewolf May 3, 2022
5f7b0ce
Collapse switch statement to new style
ZeLonewolf May 3, 2022
2a4aabe
Fix sonar findings
ZeLonewolf May 3, 2022
29e7e01
Sonar fixes
ZeLonewolf May 3, 2022
1b822bf
Spotless
ZeLonewolf May 3, 2022
5d41924
Remove unneeded public modifiers from test cases
ZeLonewolf May 3, 2022
05f1c53
Remove errant semi-colon
ZeLonewolf May 3, 2022
d1cfc3c
Move schema to samples
ZeLonewolf May 3, 2022
e244241
Add javadoc
ZeLonewolf May 3, 2022
8b00788
Simplify evaluate call
ZeLonewolf May 3, 2022
f8cbb4a
Restore original for-loop form
ZeLonewolf May 3, 2022
b9eb718
Remove unused code
ZeLonewolf May 3, 2022
4a5c7c4
Add highway areas sample
ZeLonewolf May 3, 2022
6c10670
Typo
ZeLonewolf May 3, 2022
64d9324
Add power sample
ZeLonewolf May 3, 2022
477c2a7
Clarify whole-key matching
ZeLonewolf May 3, 2022
bc71e0e
Add test case for mis-matched geometry
ZeLonewolf May 3, 2022
e731b7e
Add source type checking
ZeLonewolf May 3, 2022
3473647
Make schema check load both folders where schema files are present
ZeLonewolf May 3, 2022
57443e5
Improve loading test to actually build the schema object
ZeLonewolf May 3, 2022
124da5e
Handle case where no value producer is specified
ZeLonewolf May 3, 2022
7ce4e14
Enhanced switch statement
ZeLonewolf May 3, 2022
8a59367
Add test for bad geometry
ZeLonewolf May 3, 2022
83cc04f
Default to pass-through tagging
ZeLonewolf May 3, 2022
de1f21c
Improve zoom filter code to use MultiExpression
ZeLonewolf May 4, 2022
62d1d30
Remove intermediate variable storage
ZeLonewolf May 4, 2022
2beb0dd
Add tests for new Expression.evaluate()
ZeLonewolf May 4, 2022
7e1cc3f
Add test cases for constants
ZeLonewolf May 4, 2022
7e498af
Add matchField, fix constant test
ZeLonewolf May 4, 2022
432a31f
Add tests for different data types
ZeLonewolf May 4, 2022
d2d1bf7
Merge branch 'main' into owg_schema
ZeLonewolf May 5, 2022
d437aff
Spotless
ZeLonewolf May 5, 2022
12787da
Fix bad merge
ZeLonewolf May 5, 2022
718eb85
Remove empty() call not used
ZeLonewolf May 5, 2022
7a0282e
Add invalid schema for missing layers
ZeLonewolf May 5, 2022
5c3baed
Add manhole sample
ZeLonewolf May 5, 2022
faedcbe
Fix names
ZeLonewolf May 5, 2022
34d8379
Fix zoom-based feature config
ZeLonewolf May 5, 2022
156b39a
Update conditional zoom test
ZeLonewolf May 5, 2022
18cc10e
Add javadoc
ZeLonewolf May 5, 2022
6187db8
pull commonmark/snakeyaml dependencies into parent pom
msbarry May 9, 2022
b0ee68c
Update planetiler-custommap/src/main/java/com/onthegomap/planetiler/c…
ZeLonewolf May 9, 2022
fc13091
Update planetiler-custommap/src/main/java/com/onthegomap/planetiler/c…
ZeLonewolf May 9, 2022
932cf37
Update planetiler-custommap/src/main/java/com/onthegomap/planetiler/c…
ZeLonewolf May 9, 2022
2d84437
Fix javadoc comment
ZeLonewolf May 9, 2022
a37da53
Fix README case sensitivity
ZeLonewolf May 9, 2022
b8d9659
Add example of tag filter
ZeLonewolf May 9, 2022
b64ed13
spotless
ZeLonewolf May 10, 2022
51c433b
Fix javadoc
ZeLonewolf May 10, 2022
7537e4b
Fix javadoc
ZeLonewolf May 10, 2022
d4dd3db
Implement tag typing and renaming
ZeLonewolf May 15, 2022
4fa37f8
Handle case with no output specified
ZeLonewolf May 15, 2022
238c5cb
Switch schema definition to snake case
ZeLonewolf May 15, 2022
bb4fddb
Fix variable use
ZeLonewolf May 15, 2022
3244d07
Simpify test case name
ZeLonewolf May 15, 2022
d043dad
Fix unit test message
ZeLonewolf May 15, 2022
b42b0ac
Fix incorrect static
ZeLonewolf May 15, 2022
6445356
Extract default getter
ZeLonewolf May 15, 2022
8a6e8e5
Add links to samples
ZeLonewolf May 15, 2022
235a40d
Implement improved zoom filtering
ZeLonewolf May 16, 2022
8711ea9
Implement zoom feature visibility overrides
ZeLonewolf May 19, 2022
788082d
Fix unit tests
ZeLonewolf May 19, 2022
fb962b5
Add tests for zoom-based attributes
ZeLonewolf May 20, 2022
feef23e
Update planetiler-custommap/src/main/java/com/onthegomap/planetiler/c…
ZeLonewolf May 20, 2022
42ee90f
Update documentation
ZeLonewolf May 20, 2022
935e031
Use first match instead of smallest
ZeLonewolf May 20, 2022
2ece746
First matching rule
ZeLonewolf May 20, 2022
8cbc391
Merge branch 'owg_schema' of [email protected]:ZeLonewolf/planetiler.git…
ZeLonewolf May 20, 2022
6d33a91
Fix sonar findings
ZeLonewolf May 20, 2022
104fbc4
Change to getOrElse
ZeLonewolf May 20, 2022
56ef4c7
Convert JsonAlias->JsonProperty
ZeLonewolf May 21, 2022
0735c86
Convert to default method with NoopList
ZeLonewolf May 21, 2022
03b1f44
Extract out common method
ZeLonewolf May 21, 2022
4ffd340
Convert SchemaConfig to a record
ZeLonewolf May 21, 2022
f47ed8e
Testing to make sure files are there
ZeLonewolf May 21, 2022
be4fafb
Convert Byte->Integer for zooms
ZeLonewolf May 21, 2022
f724595
Fix code smell
ZeLonewolf May 22, 2022
019a60e
Change naming
ZeLonewolf May 22, 2022
7012cb3
Refactor map extended class
ZeLonewolf May 22, 2022
223f21f
Use static import
ZeLonewolf May 22, 2022
e7d84d1
Use newer switch/case syntax
ZeLonewolf May 22, 2022
eb4d5c2
Implement try-with-resources
ZeLonewolf May 22, 2022
d2f2b41
Fix spelling typo
ZeLonewolf May 22, 2022
02c6838
Simplify variable extraction
ZeLonewolf May 22, 2022
19480b7
Reducing visibility
ZeLonewolf May 22, 2022
1fc7e60
Expand lambda
ZeLonewolf May 22, 2022
848507a
Refactor of TagCriteria
ZeLonewolf May 22, 2022
1de8a2e
Remove unnecessary toString casts and move TagCriteria to main package
ZeLonewolf May 22, 2022
6aca644
Simplify expression
ZeLonewolf May 22, 2022
c93ec91
GeometryType and attribute processor refactor
ZeLonewolf May 22, 2022
34c76ad
Add warning to readme
ZeLonewolf May 22, 2022
ea54d29
Prepare end-to-end test
ZeLonewolf May 23, 2022
2330c7e
Fix bad maxzoom default
ZeLonewolf May 24, 2022
111a822
Adding initial end-to-end test case
ZeLonewolf May 24, 2022
bc04a0c
Add explicit public constructor
ZeLonewolf May 24, 2022
b8bce15
Add test case for geometry factory
ZeLonewolf May 24, 2022
8f2b948
Improve test cases
ZeLonewolf May 24, 2022
adc4bbc
Convert geometry test to an Expression
ZeLonewolf May 24, 2022
a552efb
Convert feature test to MultiExpression
ZeLonewolf May 24, 2022
0648dba
Add ignore entry for generated mbtiles files
ZeLonewolf May 24, 2022
48a6f2c
Fix sonar findings for diamond operator use
ZeLonewolf May 24, 2022
390d937
Add option for local sources
ZeLonewolf May 24, 2022
7fe98df
Merge branch 'onthegomap:main' into owg_schema
ZeLonewolf May 29, 2022
75b4ba7
a few tweaks
msbarry Jun 2, 2022
0843543
isEmpty check
msbarry Jun 2, 2022
6d6cd9e
Merge branch 'main' into owg_schema
ZeLonewolf Jun 2, 2022
9784568
Merge branch 'main' into owg_schema
msbarry Jun 4, 2022
cd6361d
0.5-SNAPSHOT
msbarry Jun 4, 2022
19b9c80
Update local_path.yml
ZeLonewolf Jun 7, 2022
3744ea3
switch exception type
msbarry Jun 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions planetiler-basemap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.30</version>
</dependency>
<dependency>
<groupId>org.commonmark</groupId>
<artifactId>commonmark</artifactId>
<version>0.18.2</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,25 @@ public String getString(String key, String description, String defaultValue) {
return value;
}

/** Returns a {@link Path} parsed from {@code key} argument which may or may not exist. */
/** Returns a {@link Path} parsed from {@code key} argument, or fall back to a default if the argument is not set. */
public Path file(String key, String description, Path defaultValue) {
String value = getArg(key);
Path file = value == null ? defaultValue : Path.of(value);
logArgValue(key, description, file);
return file;
}

/** Returns a {@link Path} parsed from {@code key} argument which may or may not exist. */
ZeLonewolf marked this conversation as resolved.
Show resolved Hide resolved
public Path file(String key, String description) {
String value = getArg(key);
if (value == null) {
throw new IllegalArgumentException("Missing required parameter: " + key + " (" + description + ")");
}
Path file = Path.of(value);
logArgValue(key, description, file);
return file;
}

/**
* Returns a {@link Path} parsed from {@code key} argument which must exist for the program to function.
*
Expand All @@ -221,6 +232,19 @@ public Path inputFile(String key, String description, Path defaultValue) {
return path;
}

/**
* Returns a {@link Path} parsed from a required {@code key} argument which must exist for the program to function.
*
* @throws IllegalArgumentException if the file does not exist or if the parameter is not provided.
*/
public Path inputFile(String key, String description) {
Path path = file(key, description);
if (!Files.exists(path)) {
throw new IllegalArgumentException(path + " does not exist");
}
return path;
}

/** Returns a boolean parsed from {@code key} argument where {@code "true"} is true and anything else is false. */
public boolean getBoolean(String key, String description, boolean defaultValue) {
boolean value = "true".equalsIgnoreCase(getArg(key, Boolean.toString(defaultValue)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public interface Expression {
Expression FALSE = new Constant(false, "FALSE");
BiFunction<WithTags, String, Object> GET_TAG = WithTags::getTag;

List<String> dummyList = new NoopList<>();

static And and(Expression... children) {
return and(List.of(children));
}
Expand Down Expand Up @@ -247,6 +249,26 @@ default boolean contains(Predicate<Expression> filter) {
*/
boolean evaluate(WithTags input, List<String> matchKeys);

//A list that silently drops all additions
class NoopList<T> extends ArrayList<T> {
private static final long serialVersionUID = 1L;

@Override
public boolean add(T t) {
return true;
}
}

/**
* Returns true if this expression matches an input element.
*
* @param input the input element
* @return true if this expression matches the input element
*/
default boolean evaluate(WithTags input) {
return evaluate(input, dummyList);
}

/** Returns Java code that can be used to reconstruct this expression. */
String generateJavaCode();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.onthegomap.planetiler.geo;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureCollector.Feature;
import com.onthegomap.planetiler.expression.Expression;
import java.util.function.Function;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.Lineal;
import org.locationtech.jts.geom.Polygonal;
Expand All @@ -8,8 +13,11 @@

public enum GeometryType {
UNKNOWN(VectorTileProto.Tile.GeomType.UNKNOWN, 0),
@JsonProperty("point")
POINT(VectorTileProto.Tile.GeomType.POINT, 1),
@JsonProperty("line")
LINE(VectorTileProto.Tile.GeomType.LINESTRING, 2),
@JsonProperty("polygon")
POLYGON(VectorTileProto.Tile.GeomType.POLYGON, 4);

private final VectorTileProto.Tile.GeomType protobufType;
Expand Down Expand Up @@ -49,4 +57,35 @@ public VectorTileProto.Tile.GeomType asProtobufType() {
public int minPoints() {
return minPoints;
}

/**
* Generates a factory method which creates a {@link Feature} from a {@link FeatureCollector} of the appropriate
* geometry type.
*
* @param layerName - name of the layer
* @return geometry factory method
*/
public Function<FeatureCollector, Feature> geometryFactory(String layerName) {
return switch (this) {
case POLYGON -> fc -> fc.polygon(layerName);
case LINE -> fc -> fc.line(layerName);
case POINT -> fc -> fc.point(layerName);
default -> throw new IllegalArgumentException("Unhandled geometry type " + this);
};
}

/**
* Generates a test for whether a source feature is of the correct geometry to be included in the tile.
*
* @return geometry test method
*/
public Expression featureTest() {
return switch (this) {
case POLYGON -> Expression.matchType("polygon");
case LINE -> Expression.matchType("linestring");
case POINT -> Expression.matchType("point");
default -> throw new IllegalArgumentException("Unhandled geometry type " + this);
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,18 @@ public static void assertNumFeatures(Mbtiles db, String layer, int zoom, Map<Str
}
}

public static void assertMinFeatureCount(Mbtiles db, String layer, int zoom, Map<String, Object> attrs,
Envelope envelope, int expected, Class<? extends Geometry> clazz) {
try {
int num = Verify.getNumFeatures(db, layer, zoom, attrs, envelope, clazz);

assertTrue(expected < num,
"z%d features in %s, expected at least %d got %d".formatted(zoom, layer, expected, num));
} catch (GeometryException e) {
fail(e);
}
}

public static void assertFeatureNear(Mbtiles db, String layer, Map<String, Object> attrs, double lng, double lat,
int minzoom, int maxzoom) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.onthegomap.planetiler.expression;

import static com.onthegomap.planetiler.TestUtils.newPoint;
import static com.onthegomap.planetiler.expression.Expression.*;
import static com.onthegomap.planetiler.expression.ExpressionTestUtil.featureWithTags;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.onthegomap.planetiler.reader.SimpleFeature;
import com.onthegomap.planetiler.reader.SourceFeature;
import com.onthegomap.planetiler.reader.WithTags;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Test;

Expand All @@ -22,14 +18,6 @@ class ExpressionTest {
public static final Expression.MatchAny matchCD = matchAny("c", "d");
public static final Expression.MatchAny matchBC = matchAny("b", "c");

static SourceFeature featureWithTags(String... tags) {
Map<String, Object> map = new HashMap<>();
for (int i = 0; i < tags.length; i += 2) {
map.put(tags[i], tags[i + 1]);
}
return SimpleFeature.create(newPoint(0, 0), map);
}

@Test
void testSimplify() {
assertEquals(matchAB, matchAB.simplify());
Expand Down Expand Up @@ -159,4 +147,35 @@ void testStringifyExpression() {
var expression = matchAnyTyped("key", WithTags::getDirection, 1);
assertThrows(UnsupportedOperationException.class, expression::generateJavaCode);
}

@Test
void testEvaluate() {
WithTags feature = featureWithTags("key1", "value1", "key2", "value2");

//And
assertTrue(and(matchAny("key1", "value1"), matchAny("key2", "value2")).evaluate(feature));
assertFalse(and(matchAny("key1", "value1"), matchAny("key2", "wrong")).evaluate(feature));
assertFalse(and(matchAny("key1", "wrong"), matchAny("key2", "value2")).evaluate(feature));
assertFalse(and(matchAny("key1", "wrong"), matchAny("key2", "wrong")).evaluate(feature));

//Or
assertTrue(or(matchAny("key1", "value1"), matchAny("key2", "value2")).evaluate(feature));
assertTrue(or(matchAny("key1", "value1"), matchAny("key2", "wrong")).evaluate(feature));
assertTrue(or(matchAny("key1", "wrong"), matchAny("key2", "value2")).evaluate(feature));
assertFalse(or(matchAny("key1", "wrong"), matchAny("key2", "wrong")).evaluate(feature));

//Not
assertFalse(not(matchAny("key1", "value1")).evaluate(feature));
assertTrue(not(matchAny("key1", "wrong")).evaluate(feature));

//MatchField
assertTrue(matchField("key1").evaluate(feature));
assertFalse(matchField("wrong").evaluate(feature));
assertTrue(not(matchAny("key1", "")).evaluate(feature));
assertTrue(matchAny("wrong", "").evaluate(feature));

//Constants
assertTrue(TRUE.evaluate(feature));
assertFalse(FALSE.evaluate(feature));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.onthegomap.planetiler.expression;

import static com.onthegomap.planetiler.TestUtils.newPoint;

import com.onthegomap.planetiler.reader.SimpleFeature;
import com.onthegomap.planetiler.reader.SourceFeature;
import java.util.HashMap;
import java.util.Map;

public class ExpressionTestUtil {
ZeLonewolf marked this conversation as resolved.
Show resolved Hide resolved
static SourceFeature featureWithTags(String... tags) {
Map<String, Object> map = new HashMap<>();
for (int i = 0; i < tags.length; i += 2) {
map.put(tags[i], tags[i + 1]);
}
return SimpleFeature.create(newPoint(0, 0), map);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static com.onthegomap.planetiler.TestUtils.newPoint;
import static com.onthegomap.planetiler.TestUtils.rectangle;
import static com.onthegomap.planetiler.expression.Expression.*;
import static com.onthegomap.planetiler.expression.ExpressionTest.featureWithTags;
import static com.onthegomap.planetiler.expression.ExpressionTestUtil.featureWithTags;
import static com.onthegomap.planetiler.expression.MultiExpression.entry;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.onthegomap.planetiler.geo;

import static java.util.Collections.emptyList;

import com.onthegomap.planetiler.TestUtils;
import com.onthegomap.planetiler.reader.SimpleFeature;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class GeometryTypeTest {

@Test
void testGeometryFactory() throws Exception {
Map<String, Object> tags = Map.of("key1", "value1");

var line =
SimpleFeature.createFakeOsmFeature(TestUtils.newLineString(0, 0, 1, 0, 1, 1), tags, "osm", null, 1, emptyList());
var point =
SimpleFeature.createFakeOsmFeature(TestUtils.newPoint(0, 0), tags, "osm", null, 1, emptyList());
var poly =
SimpleFeature.createFakeOsmFeature(TestUtils.newPolygon(0, 0, 1, 0, 1, 1, 0, 0), tags, "osm", null, 1,
emptyList());

Assertions.assertTrue(GeometryType.LINE.featureTest().evaluate(line));
Assertions.assertFalse(GeometryType.LINE.featureTest().evaluate(point));
Assertions.assertFalse(GeometryType.LINE.featureTest().evaluate(poly));

Assertions.assertFalse(GeometryType.POINT.featureTest().evaluate(line));
Assertions.assertTrue(GeometryType.POINT.featureTest().evaluate(point));
Assertions.assertFalse(GeometryType.POINT.featureTest().evaluate(poly));

Assertions.assertFalse(GeometryType.POLYGON.featureTest().evaluate(line));
Assertions.assertFalse(GeometryType.POLYGON.featureTest().evaluate(point));
Assertions.assertTrue(GeometryType.POLYGON.featureTest().evaluate(poly));

Assertions.assertThrows(Exception.class, () -> GeometryType.UNKNOWN.featureTest().evaluate(point));
Assertions.assertThrows(Exception.class, () -> GeometryType.UNKNOWN.featureTest().evaluate(line));
Assertions.assertThrows(Exception.class, () -> GeometryType.UNKNOWN.featureTest().evaluate(poly));
}
}
1 change: 1 addition & 0 deletions planetiler-custommap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mbtiles
Loading