-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] #7 geojson data modeling added for Geometry
- Loading branch information
Ramachandran Nellaiyappan
committed
Mar 21, 2024
1 parent
7e0d023
commit a911ecb
Showing
9 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/com/github/nramc/dev/journey/api/geojson/Geometry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.github.nramc.dev.journey.api.geojson; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.github.nramc.dev.journey.api.geojson.types.GeoJsonType; | ||
|
||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, visible = true, property = "type") | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = Point.class, name = GeoJsonType.Constants.POINT_VALUE), | ||
@JsonSubTypes.Type(value = MultiPoint.class, name = GeoJsonType.Constants.MULTI_POINT_VALUE), | ||
@JsonSubTypes.Type(value = LineString.class, name = GeoJsonType.Constants.LINE_STRING_VALUE), | ||
@JsonSubTypes.Type(value = MultiLineString.class, name = GeoJsonType.Constants.MULTI_LINE_STRING_VALUE), | ||
@JsonSubTypes.Type(value = Polygon.class, name = GeoJsonType.Constants.POLYGON_VALUE), | ||
@JsonSubTypes.Type(value = MultiPolygon.class, name = GeoJsonType.Constants.MULTI_POLYGON_VALUE), | ||
@JsonSubTypes.Type(value = GeometryCollection.class, name = GeoJsonType.Constants.GEOMETRY_COLLECTION_VALUE) | ||
}) | ||
public abstract sealed class Geometry extends GeoJson permits | ||
Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, GeometryCollection { | ||
|
||
protected Geometry(GeoJsonType type) { | ||
super(type); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/test/java/com/github/nramc/dev/journey/api/geojson/GeometryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.github.nramc.dev.journey.api.geojson; | ||
|
||
import com.github.nramc.dev.journey.api.geojson.types.GeoJsonType; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.json.JsonTest; | ||
import org.springframework.boot.test.json.JacksonTester; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@JsonTest | ||
class GeometryTest { | ||
@Autowired | ||
private JacksonTester<Geometry> jacksonTester; | ||
|
||
@Test | ||
void deserialization_withPoint() throws IOException { | ||
Geometry geometry = jacksonTester.parseObject(Files.readString(Path.of("src/test/resources/data/point.json"))); | ||
assertThat(geometry).isNotNull() | ||
.satisfies(obj -> assertThat(obj.getType()).isEqualTo(GeoJsonType.Constants.POINT_VALUE)) | ||
.isInstanceOf(Point.class); | ||
} | ||
|
||
@Test | ||
void deserialization_withMultiPoint() throws IOException { | ||
Geometry geometry = jacksonTester.parseObject(Files.readString(Path.of("src/test/resources/data/multi-point.json"))); | ||
assertThat(geometry).isNotNull() | ||
.satisfies(obj -> assertThat(obj.getType()).isEqualTo(GeoJsonType.Constants.MULTI_POINT_VALUE)) | ||
.isInstanceOf(MultiPoint.class); | ||
} | ||
|
||
@Test | ||
void deserialization_withLineString() throws IOException { | ||
Geometry geometry = jacksonTester.parseObject(Files.readString(Path.of("src/test/resources/data/line-string.json"))); | ||
assertThat(geometry).isNotNull() | ||
.satisfies(obj -> assertThat(obj.getType()).isEqualTo(GeoJsonType.Constants.LINE_STRING_VALUE)) | ||
.isInstanceOf(LineString.class); | ||
} | ||
|
||
@Test | ||
void deserialization_withMultiLineString() throws IOException { | ||
Geometry geometry = jacksonTester.parseObject(Files.readString(Path.of("src/test/resources/data/multi-line-string.json"))); | ||
assertThat(geometry).isNotNull() | ||
.satisfies(obj -> assertThat(obj.getType()).isEqualTo(GeoJsonType.Constants.MULTI_LINE_STRING_VALUE)) | ||
.isInstanceOf(MultiLineString.class); | ||
} | ||
|
||
@Test | ||
void deserialization_withPolygonAndWithoutHoles() throws IOException { | ||
Geometry geometry = jacksonTester.parseObject(Files.readString(Path.of("src/test/resources/data/polygon-without-holes.json"))); | ||
assertThat(geometry).isNotNull() | ||
.satisfies(obj -> assertThat(obj.getType()).isEqualTo(GeoJsonType.Constants.POLYGON_VALUE)) | ||
.isInstanceOf(Polygon.class); | ||
} | ||
|
||
@Test | ||
void deserialization_withPolygonAndWithHoles() throws IOException { | ||
Geometry geometry = jacksonTester.parseObject(Files.readString(Path.of("src/test/resources/data/polygon-with-holes.json"))); | ||
assertThat(geometry).isNotNull() | ||
.satisfies(obj -> assertThat(obj.getType()).isEqualTo(GeoJsonType.Constants.POLYGON_VALUE)) | ||
.isInstanceOf(Polygon.class); | ||
} | ||
|
||
@Test | ||
void deserialization_withMultiPolygon() throws IOException { | ||
Geometry geometry = jacksonTester.parseObject(Files.readString(Path.of("src/test/resources/data/multi-polygon.json"))); | ||
assertThat(geometry).isNotNull() | ||
.satisfies(obj -> assertThat(obj.getType()).isEqualTo(GeoJsonType.Constants.MULTI_POLYGON_VALUE)) | ||
.isInstanceOf(MultiPolygon.class); | ||
} | ||
|
||
@Test | ||
void deserialization_withGeometryCollection() throws IOException { | ||
Geometry geometry = jacksonTester.parseObject(Files.readString(Path.of("src/test/resources/data/geometry-collection.json"))); | ||
assertThat(geometry).isNotNull() | ||
.satisfies(obj -> assertThat(obj.getType()).isEqualTo(GeoJsonType.Constants.GEOMETRY_COLLECTION_VALUE)) | ||
.isInstanceOf(GeometryCollection.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "LineString", | ||
"coordinates": [ | ||
[101.0, 0.0], | ||
[102.0, 1.0] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"type": "MultiLineString", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 1.0] | ||
], | ||
[ | ||
[102.0, 2.0], | ||
[103.0, 3.0] | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "MultiPoint", | ||
"coordinates": [ | ||
[100.0, 0.0], | ||
[101.0, 1.0] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"type": "MultiPolygon", | ||
"coordinates": [ | ||
[ | ||
[ | ||
[102.0, 2.0], | ||
[103.0, 2.0], | ||
[103.0, 3.0], | ||
[102.0, 3.0], | ||
[102.0, 2.0] | ||
] | ||
], | ||
[ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
], | ||
[ | ||
[100.2, 0.2], | ||
[100.2, 0.8], | ||
[100.8, 0.8], | ||
[100.8, 0.2], | ||
[100.2, 0.2] | ||
] | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "Point", | ||
"coordinates": [100.0, 0.0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
], | ||
[ | ||
[100.8, 0.8], | ||
[100.8, 0.2], | ||
[100.2, 0.2], | ||
[100.2, 0.8], | ||
[100.8, 0.8] | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
} |