├── .github └── workflows │ └── java-ci.yml ├── .gitignore ├── README.md ├── copyright-template.vml ├── deploy.sh ├── docs ├── positions_hierarchy.puml └── resources │ └── positions_hierarchy.png ├── geom ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── geolatte │ │ │ └── geom │ │ │ ├── AbstractGeometryCollection.java │ │ │ ├── AbstractPositionEquality.java │ │ │ ├── AbstractPositionSequence.java │ │ │ ├── AbstractPositionSequenceBuilder.java │ │ │ ├── ApproximateGeometryEquality.java │ │ │ ├── Box.java │ │ │ ├── BufferAccessException.java │ │ │ ├── ByteBuffer.java │ │ │ ├── ByteOrder.java │ │ │ ├── C2D.java │ │ │ ├── C2DM.java │ │ │ ├── C3D.java │ │ │ ├── C3DM.java │ │ │ ├── Circle.java │ │ │ ├── Complex.java │ │ │ ├── DecimalDegree.java │ │ │ ├── DefaultMeasureGeometryOperations.java │ │ │ ├── Envelope.java │ │ │ ├── ExactPositionEquality.java │ │ │ ├── Feature.java │ │ │ ├── FeatureCollection.java │ │ │ ├── FixedSizePositionSequenceBuilder.java │ │ │ ├── G2D.java │ │ │ ├── G2DM.java │ │ │ ├── G3D.java │ │ │ ├── G3DM.java │ │ │ ├── Geometries.java │ │ │ ├── Geometry.java │ │ │ ├── GeometryCollection.java │ │ │ ├── GeometryEquality.java │ │ │ ├── GeometryOperation.java │ │ │ ├── GeometryOperations.java │ │ │ ├── GeometryPositionEquality.java │ │ │ ├── GeometryType.java │ │ │ ├── GeometryVisitor.java │ │ │ ├── JTSGeometryOperations.java │ │ │ ├── LLAPositionVisitor.java │ │ │ ├── LLAPositionVisitors.java │ │ │ ├── LineSegment.java │ │ │ ├── LineSegments.java │ │ │ ├── LineString.java │ │ │ ├── Linear.java │ │ │ ├── LinearRing.java │ │ │ ├── M.java │ │ │ ├── MeasureGeometryOperations.java │ │ │ ├── MeasureInterpolatingVisitor.java │ │ │ ├── Measured.java │ │ │ ├── MultiLineString.java │ │ │ ├── MultiPoint.java │ │ │ ├── MultiPolygon.java │ │ │ ├── NestedPositionSequence.java │ │ │ ├── PackedPositionSequence.java │ │ │ ├── Point.java │ │ │ ├── Polygon.java │ │ │ ├── Polygonal.java │ │ │ ├── Position.java │ │ │ ├── PositionEquality.java │ │ │ ├── PositionFactory.java │ │ │ ├── PositionSequence.java │ │ │ ├── PositionSequenceBuilder.java │ │ │ ├── PositionSequenceBuilders.java │ │ │ ├── PositionSequenceEquality.java │ │ │ ├── PositionSequenceIterator.java │ │ │ ├── PositionSequencePositionEquality.java │ │ │ ├── PositionVisitor.java │ │ │ ├── Positions.java │ │ │ ├── ProjectedGeometryOperations.java │ │ │ ├── Simple.java │ │ │ ├── V.java │ │ │ ├── VariableSizePositionSequenceBuilder.java │ │ │ ├── Vector.java │ │ │ ├── WithinTolerancePositionEquality.java │ │ │ ├── builder │ │ │ ├── DSL.java │ │ │ └── package.html │ │ │ ├── cga │ │ │ ├── Circle.java │ │ │ ├── CircularArcLinearizer.java │ │ │ └── NumericalMethods.java │ │ │ ├── codec │ │ │ ├── BaseWkbParser.java │ │ │ ├── BaseWkbVisitor.java │ │ │ ├── BaseWktParser.java │ │ │ ├── BaseWktWriter.java │ │ │ ├── CrsWktDecoder.java │ │ │ ├── CrsWktTokenizer.java │ │ │ ├── CrsWktVariant.java │ │ │ ├── Db2WktDecoder.java │ │ │ ├── Db2WktEncoder.java │ │ │ ├── HANAWkbDecoder.java │ │ │ ├── HANAWkbDialect.java │ │ │ ├── HANAWkbEncoder.java │ │ │ ├── HANAWktDecoder.java │ │ │ ├── HANAWktDialect.java │ │ │ ├── HANAWktEncoder.java │ │ │ ├── MySqlWkbDecoder.java │ │ │ ├── MySqlWkbDialect.java │ │ │ ├── MySqlWkbEncoder.java │ │ │ ├── PostgisWkbDecoder.java │ │ │ ├── PostgisWkbEncoder.java │ │ │ ├── PostgisWkbTypeMasks.java │ │ │ ├── PostgisWkbV1Dialect.java │ │ │ ├── PostgisWkbV2Dialect.java │ │ │ ├── PostgisWkbV2Encoder.java │ │ │ ├── PostgisWktDecoder.java │ │ │ ├── PostgisWktDialect.java │ │ │ ├── PostgisWktEncoder.java │ │ │ ├── Sfa110WkbDecoder.java │ │ │ ├── Sfa110WkbDialect.java │ │ │ ├── Sfa110WkbEncoder.java │ │ │ ├── Sfa110WktDecoder.java │ │ │ ├── Sfa110WktDialect.java │ │ │ ├── Sfa110WktEncoder.java │ │ │ ├── Sfa121WkbDecoder.java │ │ │ ├── Sfa121WkbDialect.java │ │ │ ├── Sfa121WkbEncoder.java │ │ │ ├── Sfa121WktDecoder.java │ │ │ ├── Sfa121WktDialect.java │ │ │ ├── Sfa121WktEncoder.java │ │ │ ├── SimpleTokenizer.java │ │ │ ├── UnsupportedConversionException.java │ │ │ ├── Wkb.java │ │ │ ├── WkbDecodeException.java │ │ │ ├── WkbDecoder.java │ │ │ ├── WkbDialect.java │ │ │ ├── WkbEncoder.java │ │ │ ├── WkbGeometryType.java │ │ │ ├── Wkt.java │ │ │ ├── WktDecodeException.java │ │ │ ├── WktDecoder.java │ │ │ ├── WktDialect.java │ │ │ ├── WktEncoder.java │ │ │ ├── WktKeywordToken.java │ │ │ ├── WktNumberToken.java │ │ │ ├── WktPunctuationToken.java │ │ │ ├── WktTextToken.java │ │ │ ├── WktToken.java │ │ │ ├── WktVariant.java │ │ │ ├── db │ │ │ │ ├── Decoder.java │ │ │ │ ├── Encoder.java │ │ │ │ ├── db2 │ │ │ │ │ ├── Db2ClobDecoder.java │ │ │ │ │ └── Db2ClobEncoder.java │ │ │ │ ├── oracle │ │ │ │ │ ├── AbstractSDODecoder.java │ │ │ │ │ ├── AbstractSDOEncoder.java │ │ │ │ │ ├── ConnectionFinder.java │ │ │ │ │ ├── Decoders.java │ │ │ │ │ ├── DefaultConnectionFinder.java │ │ │ │ │ ├── ElemInfo.java │ │ │ │ │ ├── Element.java │ │ │ │ │ ├── ElementType.java │ │ │ │ │ ├── Encoders.java │ │ │ │ │ ├── GeometryCollectionSdoDecoder.java │ │ │ │ │ ├── GeometryCollectionSdoEncoder.java │ │ │ │ │ ├── LineStringSdoDecoder.java │ │ │ │ │ ├── LineStringSdoEncoder.java │ │ │ │ │ ├── Linearizer.java │ │ │ │ │ ├── MultiLineSdoDecoder.java │ │ │ │ │ ├── MultiLineStringSdoEncoder.java │ │ │ │ │ ├── MultiPointSdoDecoder.java │ │ │ │ │ ├── MultiPointSdoEncoder.java │ │ │ │ │ ├── MultiPolygonSdoDecoder.java │ │ │ │ │ ├── MultiPolygonSdoEncoder.java │ │ │ │ │ ├── OracleJDBCTypeFactory.java │ │ │ │ │ ├── Ordinates.java │ │ │ │ │ ├── PointSdoDecoder.java │ │ │ │ │ ├── PointSdoEncoder.java │ │ │ │ │ ├── PolygonSdoDecoder.java │ │ │ │ │ ├── PolygonSdoEncoder.java │ │ │ │ │ ├── SDOGType.java │ │ │ │ │ ├── SDOGeometry.java │ │ │ │ │ ├── SDOPoint.java │ │ │ │ │ ├── SQLTypeFactory.java │ │ │ │ │ ├── SdoGeometryType.java │ │ │ │ │ └── Settings.java │ │ │ │ └── sqlserver │ │ │ │ │ ├── AbstractGeometryCollectionSqlServerDecoder.java │ │ │ │ │ ├── AbstractSqlServerDecoder.java │ │ │ │ │ ├── AbstractSqlServerEncoder.java │ │ │ │ │ ├── CountingPositionSequenceBuilder.java │ │ │ │ │ ├── Decoders.java │ │ │ │ │ ├── Encoders.java │ │ │ │ │ ├── Figure.java │ │ │ │ │ ├── FigureAttribute.java │ │ │ │ │ ├── GeometryCollectionSqlServerDecoder.java │ │ │ │ │ ├── GeometryCollectionSqlServerEncoder.java │ │ │ │ │ ├── IndexRange.java │ │ │ │ │ ├── LineStringSqlServerDecoder.java │ │ │ │ │ ├── LineStringSqlServerEncoder.java │ │ │ │ │ ├── MultiLineStringSqlServerDecoder.java │ │ │ │ │ ├── MultiPointSqlServerDecoder.java │ │ │ │ │ ├── MultiPolygonSqlServerDecoder.java │ │ │ │ │ ├── OpenGisType.java │ │ │ │ │ ├── PointSqlServerDecoder.java │ │ │ │ │ ├── PointSqlServerEncoder.java │ │ │ │ │ ├── PolygonSqlServerDecoder.java │ │ │ │ │ ├── PolygonSqlServerEncoder.java │ │ │ │ │ ├── Shape.java │ │ │ │ │ ├── SqlServerGeometry.java │ │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── support │ │ │ │ ├── CollectionGeometryBuilder.java │ │ │ │ ├── DecodeException.java │ │ │ │ ├── GeometryBuilder.java │ │ │ │ ├── Holder.java │ │ │ │ ├── LinearPositionsHolder.java │ │ │ │ ├── LinearPositionsListHolder.java │ │ │ │ ├── PointHolder.java │ │ │ │ ├── PolygonListHolder.java │ │ │ │ ├── SimpleGeometryBuilder.java │ │ │ │ └── package-info.java │ │ │ ├── crs │ │ │ ├── AngularUnit.java │ │ │ ├── CartesianCoordinateSystem2D.java │ │ │ ├── CartesianCoordinateSystem2DM.java │ │ │ ├── CartesianCoordinateSystem3D.java │ │ │ ├── CartesianCoordinateSystem3DM.java │ │ │ ├── CompoundCoordinateReferenceSystem.java │ │ │ ├── CoordinateReferenceSystem.java │ │ │ ├── CoordinateReferenceSystems.java │ │ │ ├── CoordinateSystem.java │ │ │ ├── CoordinateSystemAxis.java │ │ │ ├── CoordinateSystemAxisDirection.java │ │ │ ├── CrsExtendedId.java │ │ │ ├── CrsId.java │ │ │ ├── CrsIdentifiable.java │ │ │ ├── CrsParameter.java │ │ │ ├── CrsRegistry.java │ │ │ ├── Datum.java │ │ │ ├── Ellipsoid.java │ │ │ ├── EllipsoidalAxis.java │ │ │ ├── EllipsoidalCoordinateSystem2D.java │ │ │ ├── EllipsoidalCoordinateSystem2DM.java │ │ │ ├── EllipsoidalCoordinateSystem3D.java │ │ │ ├── EllipsoidalCoordinateSystem3DM.java │ │ │ ├── EllipsoidalHeightCSAXis.java │ │ │ ├── Extension.java │ │ │ ├── GeocentricCartesianCoordinateReferenceSystem.java │ │ │ ├── GeodeticLatitudeCSAxis.java │ │ │ ├── GeodeticLongitudeCSAxis.java │ │ │ ├── Geographic2DCoordinateReferenceSystem.java │ │ │ ├── Geographic3DCoordinateReferenceSystem.java │ │ │ ├── GeographicCoordinateReferenceSystem.java │ │ │ ├── InconsistentCoordinateSystemException.java │ │ │ ├── LinearCoordinateReferenceSystem.java │ │ │ ├── LinearUnit.java │ │ │ ├── MeasureStraightLineAxis.java │ │ │ ├── OneDimensionCoordinateReferenceSystem.java │ │ │ ├── OneDimensionCoordinateSystem.java │ │ │ ├── PrimeMeridian.java │ │ │ ├── ProjectedCoordinateReferenceSystem.java │ │ │ ├── Projection.java │ │ │ ├── SingleCoordinateReferenceSystem.java │ │ │ ├── StraightLineAxis.java │ │ │ ├── Unit.java │ │ │ ├── UnsupportedCoordinateReferenceSystem.java │ │ │ ├── VerticalCoordinateReferenceSystem.java │ │ │ ├── VerticalDatum.java │ │ │ ├── VerticalStraightLineAxis.java │ │ │ ├── package.html │ │ │ └── trans │ │ │ │ ├── ConcatenatedOperation.java │ │ │ │ ├── CoordinateFrameRotation.java │ │ │ │ ├── CoordinateOperation.java │ │ │ │ ├── CoordinateOperations.java │ │ │ │ ├── EnvelopeTransform.java │ │ │ │ ├── Geographic3DTo2DConversion.java │ │ │ │ ├── GeographicToGeocentricConversion.java │ │ │ │ ├── PositionVectorTransformation.java │ │ │ │ ├── TransformOperation.java │ │ │ │ ├── TransformOperations.java │ │ │ │ ├── TransformVisitor.java │ │ │ │ ├── UnsupportedTransformException.java │ │ │ │ ├── WithEpsgGOperationMethod.java │ │ │ │ └── projections │ │ │ │ ├── LambertConformalConic2SP.java │ │ │ │ ├── Projections.java │ │ │ │ └── PseudoMercator.java │ │ │ ├── curve │ │ │ ├── MortonCode.java │ │ │ ├── MortonContext.java │ │ │ └── package-info.java │ │ │ ├── generator │ │ │ ├── AbstractGeometryGenerator.java │ │ │ ├── Choice.java │ │ │ ├── CombinedGeometryGenerator.java │ │ │ ├── DefaultGeometryCollectionGenerator.java │ │ │ ├── DefaultLineStringGenerator.java │ │ │ ├── DefaultMultiLineStringGenerator.java │ │ │ ├── DefaultMultiPointGenerator.java │ │ │ ├── DefaultMultiPolygonGenerator.java │ │ │ ├── DefaultPointGenerator.java │ │ │ ├── DefaultPolygonGenerator.java │ │ │ ├── Generator.java │ │ │ ├── GeometryGenerators.java │ │ │ ├── PositionGenerator.java │ │ │ ├── PropertyMapGenerator.java │ │ │ └── ValueGeneratorFactory.java │ │ │ ├── jts │ │ │ ├── JTS.java │ │ │ ├── JTSConversionException.java │ │ │ ├── JTSUtils.java │ │ │ ├── PointSequenceCoordinateSequenceFactory.java │ │ │ └── package-info.java │ │ │ └── package.html │ └── resources │ │ ├── spatial_ref_sys.txt │ │ └── spatial_ref_sys_license │ └── test │ ├── java │ ├── TestSettings.java │ └── org │ │ └── geolatte │ │ ├── geom │ │ ├── AssertHelpers.java │ │ ├── BoxTest.java │ │ ├── CastBehaviorTest.java │ │ ├── ContainsTest.java │ │ ├── CrsMock.java │ │ ├── DecimalDegreeTest.java │ │ ├── ExactCoordinatePositionEqualityTest.java │ │ ├── ForceToCrsTest.java │ │ ├── LineSegmentsTest.java │ │ ├── LineStringTest.java │ │ ├── LinearRingTest.java │ │ ├── MeasuredTestCases.java │ │ ├── MultiLineStringTest.java │ │ ├── MultiPointTest.java │ │ ├── NestedPositionSequenceTest.java │ │ ├── PackedPointSequenceTest.java │ │ ├── PointTest.java │ │ ├── PolygonTest.java │ │ ├── PositionSequenceBuilderTest.java │ │ ├── PositionSequenceIteratorTest.java │ │ ├── PositionSequencePositionEqualityTest.java │ │ ├── PositionTest.java │ │ ├── SerializableTest.java │ │ ├── TestDefaultMeasureGeometryOperations.java │ │ ├── TestEnvelope.java │ │ ├── TestJTSGeometryOperations.java │ │ ├── TestVector.java │ │ ├── VariableSizePointSequenceBuilderTest.java │ │ ├── builder │ │ │ └── client │ │ │ │ └── DslTest.java │ │ ├── cga │ │ │ ├── CircleTest.java │ │ │ ├── CircularArcLinearizerTest.java │ │ │ └── NumericalMethodsTest.java │ │ ├── codec │ │ │ ├── HANACodecUnitTests.java │ │ │ ├── MySqlCodecUnitTests.java │ │ │ ├── TestByteBuffer.java │ │ │ ├── TestByteBufferInvalidCharacters.java │ │ │ ├── TestCrsWktDecoder.java │ │ │ ├── TestCrsWktTokenizer.java │ │ │ ├── TestCrsWktWordMatcher.java │ │ │ ├── TestEWktDecodingWithCrsSpecified.java │ │ │ ├── TestMySqlWkbCodec.java │ │ │ ├── TestPostgisJDBCUnitTests.java │ │ │ ├── TestPostgisJDBCWithSRIDUnitTests.java │ │ │ ├── TestPostgisWkbEncoderDecoder.java │ │ │ ├── TestPostgisWkbV2EncoderDecoder.java │ │ │ ├── TestPostgisWktEncoderDecoder.java │ │ │ ├── TestSfa110WktWkbCodec.java │ │ │ ├── TestSfa121WktWkbCodec.java │ │ │ ├── TestSimpleTokenizer.java │ │ │ ├── TestWkbCodecBugs.java │ │ │ ├── TestWkbDecodingIdempotent.java │ │ │ ├── TestWktDecodingBugs.java │ │ │ ├── TestWktDecodingIdempotent.java │ │ │ ├── db │ │ │ │ ├── db2 │ │ │ │ │ └── Db2ClobEncoderDecoderTest.java │ │ │ │ ├── oracle │ │ │ │ │ ├── GeogratTests.java │ │ │ │ │ ├── SDOElemInfoSpecTest.java │ │ │ │ │ ├── SDOElemInfoTest.java │ │ │ │ │ ├── SDOGTypeTest.java │ │ │ │ │ ├── SDOGeometryHelper.java │ │ │ │ │ ├── SmallArcBugTest.java │ │ │ │ │ ├── TestForIssue140.java │ │ │ │ │ ├── TestForIssue67.java │ │ │ │ │ ├── TestGeometryCollectionSdoDecoder.java │ │ │ │ │ ├── TestGeometryCollectionSdoEncoder.java │ │ │ │ │ ├── TestLineStringSdoDecoder.java │ │ │ │ │ ├── TestLineStringSdoEncoder.java │ │ │ │ │ ├── TestMultiLineSdoCodec.java │ │ │ │ │ ├── TestMultiPointSdoCodec.java │ │ │ │ │ ├── TestMultiPolygonSdoCodec.java │ │ │ │ │ ├── TestPointSdoDecoder.java │ │ │ │ │ ├── TestPointSdoEncoder.java │ │ │ │ │ ├── TestPolygonSdoDecoder.java │ │ │ │ │ ├── TestPolygonSdoEncoder.java │ │ │ │ │ ├── TestSdoEncodeBug78.java │ │ │ │ │ └── TestSdoGeometryPointDecoder.java │ │ │ │ └── sqlserver │ │ │ │ │ └── TestSqlServerCodec.java │ │ │ └── testcases │ │ │ │ ├── BoundingBoxTest.java │ │ │ │ ├── CodecUnitTestBase.java │ │ │ │ ├── HANAJDBCUnitTestInputs.java │ │ │ │ ├── HANAJDBCWithSRIDTestInputs.java │ │ │ │ ├── MySqlUnitTestInputs.java │ │ │ │ ├── PostgisJDBCUnitTestInputs.java │ │ │ │ ├── PostgisJDBCWithSRIDTestInputs.java │ │ │ │ ├── PostgisTestCases.java │ │ │ │ ├── Sfa110WktWkbTestCases.java │ │ │ │ ├── Sfa121WktWkbTestCases.java │ │ │ │ ├── WktWkbCodecTestBase.java │ │ │ │ └── XmlDatabaseCodecTestCases.java │ │ ├── crs │ │ │ ├── SerializableTest.java │ │ │ ├── TestCoordinateReferenceSystem.java │ │ │ ├── TestCrsExtendedId.java │ │ │ ├── TestCrsId.java │ │ │ ├── TestCrsIdenttity.java │ │ │ ├── testCrsRegistry.java │ │ │ └── trans │ │ │ │ ├── ConcatenatedCoordinateOperationTest.java │ │ │ │ ├── CoordinateOperationsTest.java │ │ │ │ ├── GeographicToGeocentricConversionTest.java │ │ │ │ ├── PositionVectorTransformationTest.java │ │ │ │ ├── TestEnvelopeTransform.java │ │ │ │ ├── TestTransformVisitor.java │ │ │ │ ├── TestTransformVisitorExt.java │ │ │ │ └── projections │ │ │ │ ├── LambertCC2SPTest.java │ │ │ │ └── PseudoMercatorTest.java │ │ ├── curve │ │ │ ├── MortonCodeTest.java │ │ │ └── MortonContextTest.java │ │ ├── generators │ │ │ └── GeneratorsTest.java │ │ ├── jts │ │ │ ├── JTSUtilsTest.java │ │ │ ├── ReverseTest.java │ │ │ └── TestJTS.java │ │ └── support │ │ │ └── generator │ │ │ ├── CircleGenerator.java │ │ │ ├── Generator.java │ │ │ ├── PositionGenerator.java │ │ │ └── StdGenerators.java │ │ └── test │ │ └── GeometryApiTest.java │ └── resources │ ├── log4j.properties │ └── sqlserver-test-data.xml ├── json ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── geolatte │ │ └── geom │ │ └── json │ │ ├── BoxSerializer.java │ │ ├── CrsDeserializer.java │ │ ├── CrsSerializer.java │ │ ├── FeatureCollectionDeserializer.java │ │ ├── FeatureCollectionSerializer.java │ │ ├── FeatureDeserializer.java │ │ ├── FeatureSerializer.java │ │ ├── GeoJsonFeature.java │ │ ├── GeoJsonFeatureCollection.java │ │ ├── GeoJsonProcessingException.java │ │ ├── GeolatteGeomModule.java │ │ ├── GeometryDeserializer.java │ │ ├── GeometrySerializer.java │ │ ├── Setting.java │ │ └── Settings.java │ └── test │ └── java │ └── org │ └── geolatte │ └── geom │ └── json │ ├── CrsDynamicegistrationTest.java │ ├── CrsSupportTest.java │ ├── Crss.java │ ├── FeatureCollectionDeserializationTest.java │ ├── FeatureCollectionSerializationTest.java │ ├── FeatureDeserializationTest.java │ ├── FeatureSerializationTest.java │ ├── ForceCrsToDefaultTest.java │ ├── GeoJsonStrings.java │ ├── GeoJsonTest.java │ ├── GeometryCollectionSerializationTest.java │ ├── GeometryColllectionDeserializationTest.java │ ├── GeometryDeserializationTest.java │ ├── IgnoreCrsTest.java │ ├── LineStringDeserializationTest.java │ ├── LineStringSerializationTest.java │ ├── MultiLineStringDeserializationTest.java │ ├── MultiLineStringSerializationTest.java │ ├── MultiPointDeserializationTest.java │ ├── MultiPointSerializationTest.java │ ├── MultiPolygonDeserializationTest.java │ ├── MultiPolygonSerializationTest.java │ ├── PointDeserializationTest.java │ ├── PointSerializationTest.java │ ├── PolygonDeserializerTest.java │ ├── PolygonSerializationTest.java │ └── UrnCrsSupportTest.java ├── pom.xml └── scala ├── .scalafmt.conf ├── build.sbt ├── circe-geojson └── src │ ├── main │ └── scala │ │ └── org │ │ └── geolatte │ │ └── geom │ │ └── circe │ │ ├── GeoJsonCodec.scala │ │ └── WktJsonCodec.scala │ └── test │ └── scala │ └── org │ └── geolatte │ └── geom │ └── circejson │ ├── GeoJsonGen.scala │ ├── GeometryDecodersSpec.scala │ ├── GeometryEncodersSpec.scala │ └── WktJsonCodecSpec.scala ├── geom └── src │ ├── main │ └── scala │ │ └── org │ │ └── geolatte │ │ └── geom │ │ └── syntax │ │ └── GeometryImplicits.scala │ └── test │ └── scala │ └── org │ └── geolatte │ └── geom │ └── syntax │ └── ImplicitConversionTests.scala ├── play-json-28 └── src │ ├── main │ └── scala │ │ └── org │ │ └── geolatte │ │ └── geom │ │ └── playjson │ │ └── GeometryJsonFormats.scala │ └── test │ └── scala │ └── org │ └── geolatte │ └── geom │ └── playjson │ ├── GeoJsonStringGenerator.scala │ └── GeometryReadersTest.scala ├── project ├── build.properties └── plugins.sbt └── slick └── src └── main └── scala └── org └── geolatte └── slick └── GeolattePgPostGISSupport.scala /.github/workflows/java-ci.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build_on_jdk11: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v4 11 | - name: Set up JDK 11 12 | uses: actions/setup-java@v4 13 | with: 14 | java-version: 11 15 | distribution: 'temurin' 16 | - name: Cache Maven packages 17 | uses: actions/cache@v4 18 | with: 19 | path: ~/.m2 20 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 21 | restore-keys: ${{ runner.os }}-m2 22 | - name: Build with Maven 23 | run: mvn --batch-mode --update-snapshots verify 24 | 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | atlassian-ide-plugin.xml 2 | *.idea 3 | *.iml 4 | *.ipr 5 | *.iws 6 | target 7 | javadoc/* 8 | **/.classpath 9 | **/.project 10 | **/.settings 11 | **/bin**/logs/ 12 | **/project/*-shim.sbt 13 | **/project/project/ 14 | **/project/target/ 15 | **/target/ 16 | **/.flattened-pom.xml 17 | deploy-release.sh 18 | .sdkmanrc 19 | -------------------------------------------------------------------------------- /copyright-template.vml: -------------------------------------------------------------------------------- 1 | This file is part of the GeoLatte project. 2 | 3 | GeoLatte is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | GeoLatte is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Lesser General Public License for more details. 12 | 13 | You should have received a copy of the GNU Lesser General Public License 14 | along with GeoLatte. If not, see . 15 | 16 | Copyright (C) 2010 - $today.year and Ownership of code is shared by: 17 | Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 18 | Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | #ensure we use java 8 4 | . ~/.sdkman/bin/sdkman-init.sh 5 | sdk env 6 | 7 | mvn -P release clean deploy 8 | -------------------------------------------------------------------------------- /docs/positions_hierarchy.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | 3 | abstract class Position 4 | interface Measured 5 | 6 | Position <|-- G2D 7 | G2D <|-- G2DM 8 | Measured <|-- G2DM 9 | G2D <|-- G3D 10 | 11 | G3D <|-- G3DM 12 | Measured <|-- G3DM 13 | 14 | 15 | Position <|-- C2D 16 | C2D <|-- C2DM 17 | Measured <|-- C2DM 18 | C2D <|-- C3D 19 | 20 | C3D <|-- C3DM 21 | Measured <|-- C3DM 22 | @enduml -------------------------------------------------------------------------------- /docs/resources/positions_hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeoLatte/geolatte-geom/54bd3f8ecc73c3c9d17fd5d84ccf1d936afbeefd/docs/resources/positions_hierarchy.png -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/ApproximateGeometryEquality.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 2019-03-27. 5 | */ 6 | public class ApproximateGeometryEquality extends GeometryPositionEquality { 7 | 8 | 9 | /** 10 | * Constructs an instance that determines equality by comparing the positions to within the 11 | * specified precision 12 | * 13 | * @param precision the precision to use when determining equality 14 | */ 15 | public ApproximateGeometryEquality(double precision) { 16 | super(new WithinTolerancePositionEquality(precision)); 17 | } 18 | 19 | @Override 20 | public

boolean equals(Geometry

first, Geometry

second) { 21 | return super.equals(first, second); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/BufferAccessException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2012 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom; 23 | 24 | /** 25 | * An exception for Buffer over- or underflow. 26 | * 27 | * @author Karel Maesen, Geovise BVBA 28 | * creation-date: 9/29/12 29 | */ 30 | public class BufferAccessException extends RuntimeException { 31 | 32 | public BufferAccessException(String msg) { 33 | super(msg); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/C2D.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * A position in a cartesian coordinate reference system. 5 | * 6 | * @author Karel Maesen, Geovise BVBA 7 | * creation-date: 2/19/14 8 | */ 9 | public class C2D extends Position { 10 | 11 | /** 12 | * Constructs an empty instance 13 | */ 14 | public C2D() { 15 | super(); 16 | } 17 | 18 | /** 19 | * Constructs an instance with the specified x (EASTING or WESTING) or y (NORTHING or SOUTHING) coordinates 20 | * 21 | * {@link org.geolatte.geom.crs.CoordinateReferenceSystem}, the

22 | * @param x coordinate for axis in EAST or WEST direction 23 | * @param y coordinate for axis in NORTH or SOUTH direction 24 | */ 25 | public C2D(double x, double y) { 26 | super(x, y); 27 | } 28 | 29 | protected C2D(double... coords) { 30 | super(coords); 31 | } 32 | 33 | @Override 34 | public int getCoordinateDimension() { 35 | return 2; 36 | } 37 | 38 | /** 39 | * Returns the coordinate for EAST (WEST) axis direction 40 | * 41 | * @return the coordinate for EAST (WEST) axis direction 42 | */ 43 | public double getX() { 44 | return getCoordinate(0); 45 | } 46 | 47 | /** 48 | * Returns the coordinate for NORTH (SOUTH) axis direction 49 | * 50 | * @return the coordinate for NORTH (SOUTH) axis direction 51 | */ 52 | public double getY() { 53 | return getCoordinate(1); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/C2DM.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * A cartesian {@code Position} with a measure value. 5 | * 6 | * @author Karel Maesen, Geovise BVBA 7 | * creation-date: 2/19/14 8 | */ 9 | public class C2DM extends C2D implements Measured { 10 | 11 | 12 | public C2DM() { 13 | super(); 14 | } 15 | 16 | public C2DM(double x, double y, double m) { 17 | super(x, y, m); 18 | } 19 | 20 | @Override 21 | public int getCoordinateDimension() { 22 | return 3; 23 | } 24 | 25 | @Override 26 | public double getM() { 27 | return getCoordinate(2); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/C3D.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * A cartesian {@code Position} having an z-value. 5 | * 6 | * @author Karel Maesen, Geovise BVBA 7 | * creation-date: 2/19/14 8 | */ 9 | public class C3D extends C2D { 10 | 11 | public C3D() { 12 | super(); 13 | } 14 | 15 | public C3D(double x, double y, double z) { 16 | super(x, y, z); 17 | } 18 | 19 | protected C3D(double... coords) { 20 | super(coords); 21 | } 22 | 23 | public double getZ() { 24 | return getCoordinate(2); 25 | } 26 | 27 | @Override 28 | public int getCoordinateDimension() { 29 | return 3; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/C3DM.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * A cartesian {@code Position} with both an z and a measure value. 5 | * 6 | * @author Karel Maesen, Geovise BVBA 7 | * creation-date: 2/19/14 8 | */ 9 | public class C3DM extends C3D implements Measured { 10 | 11 | public C3DM() { 12 | super(); 13 | } 14 | 15 | public C3DM(double x, double y, double z, double m) { 16 | super(x, y, z, m); 17 | } 18 | 19 | @Override 20 | public double getM() { 21 | return getCoordinate(3); 22 | } 23 | 24 | @Override 25 | public int getCoordinateDimension() { 26 | return 4; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/ExactPositionEquality.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2012 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom; 23 | 24 | /** 25 | * A {@link PositionEquality} implementation that considers two Positions to be equal if and only if 26 | * the have the same coordinates. 27 | * dimensions. 28 | * 29 | * @author Karel Maesen, Geovise BVBA 30 | * creation-date: 4/13/12 31 | */ 32 | public class ExactPositionEquality extends AbstractPositionEquality { 33 | 34 | @Override 35 | protected boolean equals(double co1, double co2) { 36 | return co1 == co2; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/Feature.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Models a spatial feature 7 | * 8 | * Created by Karel Maesen, Geovise BVBA on 13/07/2018. 9 | */ 10 | public interface Feature< P extends Position, ID> { 11 | 12 | final static String TYPE = "Feature"; 13 | 14 | Geometry

getGeometry(); 15 | 16 | ID getId(); 17 | 18 | Map getProperties(); 19 | 20 | Box

getBbox(); 21 | 22 | default String getType(){ 23 | return TYPE; 24 | } 25 | 26 | default Object getProperty(String propertyName) { 27 | return getProperties().get(propertyName); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/FeatureCollection.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | import java.util.List; 4 | 5 | public interface FeatureCollection

{ 6 | 7 | String TYPE = "FeatureCollection"; 8 | 9 | List> getFeatures(); 10 | 11 | Box

getBbox(); 12 | 13 | default String getType() { 14 | return TYPE; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/G2D.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * A {@code Position} in a geographic coordinate reference system. 5 | * 6 | * @author Karel Maesen, Geovise BVBA 7 | * creation-date: 2/19/14 8 | */ 9 | public class G2D extends Position { 10 | 11 | 12 | /** 13 | * Constructs an empty instance 14 | */ 15 | public G2D() { 16 | super(); 17 | } 18 | 19 | /** 20 | * Constructs an instance with the specified longitude and latitude 21 | * 22 | * @param lon the longitude 23 | * @param lat the latitude 24 | */ 25 | public G2D(double lon, double lat) { 26 | super(lon, lat); 27 | } 28 | 29 | /** 30 | * Constructs an instance from the specified coordinates. 31 | * 32 | * It expects first the longitude, then the latitude coordinate 33 | * @param coords 34 | */ 35 | protected G2D(double... coords) { 36 | super(coords); 37 | } 38 | 39 | /** 40 | * Returns the longitude of this position 41 | * @return the longitude of this position 42 | */ 43 | public double getLon() { 44 | return getCoordinate(0); 45 | } 46 | 47 | /** 48 | * Returns the latitude of this position 49 | * @return the latitude of this position 50 | */ 51 | public double getLat() { 52 | return getCoordinate(1); 53 | } 54 | 55 | @Override 56 | public int getCoordinateDimension() { 57 | return 2; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/G2DM.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * A geographic {@code Position} with a measure value. 5 | * 6 | * @author Karel Maesen, Geovise BVBA 7 | * creation-date: 2/19/14 8 | */ 9 | public class G2DM extends G2D implements Measured { 10 | 11 | 12 | public G2DM() { 13 | super(); 14 | } 15 | 16 | public G2DM(double lon, double lat, double m) { 17 | super(lon, lat, m); 18 | } 19 | 20 | @Override 21 | public double getM() { 22 | return getCoordinate(2); 23 | } 24 | 25 | @Override 26 | public int getCoordinateDimension() { 27 | return 3; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/G3D.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * A geographic {@code Position} with an altitude. 5 | * 6 | * @author Karel Maesen, Geovise BVBA 7 | * creation-date: 2/19/14 8 | */ 9 | public class G3D extends G2D { 10 | 11 | public G3D() { 12 | super(); 13 | } 14 | 15 | public G3D(double lon, double lat, double alt) { 16 | super(lon, lat, alt); 17 | } 18 | 19 | protected G3D(double... coords) { 20 | super(coords); 21 | } 22 | 23 | public double getHeight() { 24 | return getCoordinate(2); 25 | } 26 | 27 | @Override 28 | public int getCoordinateDimension() { 29 | return 3; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/G3DM.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * A geographic {@code Position} with both an altitude and a measure value. 5 | * 6 | * @author Karel Maesen, Geovise BVBA 7 | * creation-date: 2/19/14 8 | */ 9 | public class G3DM extends G3D implements Measured { 10 | 11 | public G3DM() { 12 | super(); 13 | } 14 | 15 | public G3DM(double lon, double lat, double alt, double m) { 16 | super(lon, lat, alt, m); 17 | } 18 | 19 | @Override 20 | public double getM() { 21 | return getCoordinate(3); 22 | } 23 | 24 | @Override 25 | public int getCoordinateDimension() { 26 | return 4; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/GeometryCollection.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 4 | 5 | /** 6 | * Created by Karel Maesen, Geovise BVBA on 2019-07-29. 7 | */ 8 | public class GeometryCollection

extends AbstractGeometryCollection> { 9 | 10 | 11 | @SafeVarargs 12 | public GeometryCollection(Geometry

... geoms) { 13 | super(geoms); 14 | } 15 | 16 | public GeometryCollection(CoordinateReferenceSystem

crs) { 17 | super(crs); 18 | } 19 | 20 | @SuppressWarnings("unchecked") 21 | public GeometryCollection as(Class castToType){ 22 | checkCast(castToType); 23 | return (GeometryCollection)this; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/GeometryEquality.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2012 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom; 23 | 24 | /** 25 | * A test for equality of Geometrys. 26 | * 27 | * @author Karel Maesen, Geovise BVBA 28 | * creation-date: 4/13/12 29 | */ 30 | public interface GeometryEquality { 31 | 32 | /** 33 | * Checks whether the first geometry equals 34 | * the second, for some definition of equality. 35 | * 36 | * @param first a Geometry 37 | * @param second a second Geometry 38 | * @return true if and only if both both Geometrys are equal. 39 | */ 40 | public

boolean equals(Geometry

first, Geometry

second); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/GeometryOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2011 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom; 23 | 24 | /** 25 | * An operation that can be executed on a Geometry. 26 | * 27 | *

The GeometryOperation interface makes it easy to use the Strategy Pattern and implement different 28 | * algorithms for certain geometric or topological operations.

29 | * 30 | * @author Karel Maesen, Geovise BVBA 31 | * creation-date: 5/3/11 32 | * 33 | * @param the return type of the operation 34 | */ 35 | public interface GeometryOperation { 36 | 37 | /** 38 | * Executes the operation. 39 | * 40 | * @return the result of this operation 41 | */ 42 | public R execute(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/GeometryOperations.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * Factory methods for Geometry Operations instances. 5 | */ 6 | public class GeometryOperations { 7 | 8 | /** 9 | * Create an instance of {@code ProjectedGeometryOperations} 10 | * 11 | * @return 12 | */ 13 | public static ProjectedGeometryOperations projectedGeometryOperations() { 14 | return ProjectedGeometryOperations.Default; 15 | } 16 | 17 | /** 18 | * Create an instance of {@code MeasureGeometryOperations} 19 | * 20 | * @return 21 | */ 22 | public static MeasureGeometryOperations measureGeometryOperations() { 23 | return MeasureGeometryOperations.Default; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/LLAPositionVisitor.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * A low-level access Position Visitor. 5 | * 6 | *

This visitor is for high performance applications. The PositionSequence that accepts the visitor passes each 7 | * coordinate as an array.

8 | * 9 | * @see org.geolatte.geom.PositionSequence#accept(LLAPositionVisitor) 10 | * 11 | * @author Karel Maesen, Geovise BVBA 12 | * creation-date: 3/4/14 13 | */ 14 | public interface LLAPositionVisitor { 15 | 16 | 17 | /** 18 | * The visit method that is executed for each coordinate. 19 | * 20 | * @param coordinate the visited coordinate in array representation 21 | * 22 | */ 23 | public void visit(double[] coordinate); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/LLAPositionVisitors.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | public class LLAPositionVisitors { 4 | 5 | static public

LLAPositionVisitor mkCombiningVisitor(PositionSequenceBuilder

builder){ 6 | return new CombiningVisitor<>(builder); 7 | } 8 | } 9 | 10 | class CombiningVisitor

implements LLAPositionVisitor { 11 | 12 | final PositionSequenceBuilder

builder; 13 | 14 | CombiningVisitor(PositionSequenceBuilder

builder) { 15 | this.builder = builder; 16 | } 17 | 18 | /** 19 | * The visit method that is executed for each coordinate. 20 | * 21 | * @param coordinate the visited coordinate in array representation 22 | */ 23 | @Override 24 | public void visit(double[] coordinate) { 25 | this.builder.add(coordinate); 26 | } 27 | 28 | PositionSequence

result() { 29 | return builder.toPositionSequence(); 30 | } 31 | } -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/Linear.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2014 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom; 23 | 24 | /** 25 | * An interface for linear {@code Geometry}s 26 | * 27 | * @author Karel Maesen, Geovise BVBA 28 | * creation-date: 3/27/14 29 | */ 30 | public interface Linear

{ 31 | 32 | /** 33 | * Returns the start position of the linear {@code Geometry} 34 | * 35 | * @return the start position of the linear {@code Geometry} 36 | */ 37 | public P getStartPosition(); 38 | 39 | /** 40 | * Returns the end position of the linear {@code Geometry} 41 | * 42 | * @return the end position of the linear {@code Geometry} 43 | */ 44 | public P getEndPosition(); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/M.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 29/11/14. 5 | */ 6 | public class M extends Position { 7 | 8 | /** 9 | * Constructs an empty instance 10 | */ 11 | public M() { 12 | super(); 13 | } 14 | 15 | /** 16 | * Constructs an instance with the specified longitude and latitude 17 | * 18 | * @param value the vertical value 19 | */ 20 | public M(double value) { 21 | super(value); 22 | } 23 | 24 | /** 25 | * Constructs an instance from the specified coordinates. 26 | * 27 | * It expects first the longitude, then the latitude coordinate 28 | * 29 | * @param coords 30 | */ 31 | protected M(double... coords) { 32 | super(coords); 33 | } 34 | 35 | public double getValue() { 36 | return getCoordinate(0); 37 | } 38 | 39 | @Override 40 | public int getCoordinateDimension() { 41 | return 1; 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/Measured.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * Interface for {@code Position}s that have a "measure" value. 5 | * 6 | * @author Karel Maesen, Geovise BVBA 7 | * creation-date: 2/19/14 8 | */ 9 | public interface Measured { 10 | 11 | /** 12 | * Returns the measure value of this instance. 13 | * 14 | * @return the measure value of this instance. 15 | */ 16 | double getM(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/Polygonal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2014 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom; 23 | 24 | /** 25 | * Marker interface for Polygonal {@code Geometry}s. 26 | * 27 | * @author Karel Maesen, Geovise BVBA 28 | * creation-date: 3/27/14 29 | */ 30 | public interface Polygonal

{ 31 | 32 | } 33 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/PositionFactory.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by Karel Maesen, Geovise BVBA on 28/11/14. 7 | */ 8 | public interface PositionFactory

extends Serializable { 9 | 10 | public Class

forClass(); 11 | 12 | public int getCoordinateDimension(); 13 | 14 | public P mkPosition(double... coordinates); 15 | 16 | //the next three methods are required for interoperability with JTS coordinates 17 | 18 | public boolean hasZComponent(); 19 | 20 | public boolean hasMComponent(); 21 | 22 | public int getMComponentIndex(); 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/PositionSequenceEquality.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2012 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom; 23 | 24 | /** 25 | * A test for PositionSequence equality. 26 | * 27 | *

Implementations must be thread-safe.

28 | * 29 | * @author Karel Maesen, Geovise BVBA 30 | * creation-date: 4/13/12 31 | */ 32 | public interface PositionSequenceEquality { 33 | 34 | /** 35 | * Tests whether two PositionSequences are equal. 36 | * 37 | * @param first 38 | * @param second 39 | * @return true if two PositionSequences are equal, false otherwise. 40 | */ 41 | public

boolean equals(PositionSequence

first, PositionSequence

second); 42 | 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/PositionVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2011 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom; 23 | 24 | /** 25 | * A visitor for Positions. 26 | * 27 | * @author Karel Maesen, Geovise BVBA 28 | * creation-date: 5/3/11 29 | */ 30 | public interface PositionVisitor

{ 31 | 32 | /** 33 | * The visit method to be executed for each Position 34 | * 35 | * @param position Position to visit 36 | */ 37 | public void visit(P position); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/Simple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2014 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom; 23 | 24 | /** 25 | * Marker interface for simple {@code Geometry}s, i.e. {@code Geometry}s that are not composed of other 26 | * {@code Geometry}s 27 | * 28 | * @author Karel Maesen, Geovise BVBA 29 | * creation-date: 5/16/14 30 | */ 31 | public interface Simple { 32 | } 33 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/V.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 29/11/14. 5 | */ 6 | public class V extends Position{ 7 | 8 | /** 9 | * Constructs an empty instance 10 | */ 11 | public V() { 12 | super(); 13 | } 14 | 15 | /** 16 | * Constructs an instance with the specified vertical value 17 | * 18 | * @param value the vertical value 19 | */ 20 | public V(double value) { 21 | super(value); 22 | } 23 | 24 | /** 25 | * Constructs an instance from the specified coordinate. 26 | * 27 | * @param coords 28 | */ 29 | protected V(double... coords) { 30 | super(coords); 31 | } 32 | 33 | public double getValue() { 34 | return getCoordinate(0); 35 | } 36 | 37 | @Override 38 | public int getCoordinateDimension() { 39 | return 1; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/builder/package.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 24 | 25 | 26 | Geolatte Geometry DSL 27 | 28 | 29 | 30 |

A DSL to simplify the creation of Geometries.

31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Db2WktDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | /** 4 | * An EWKT decoder for DB2 as used in Hibernate Spatial 5 | *

6 | *

7 | * Note:this Decoder is to be used in combination with the DB2 EWKT transform group created by David Adler.See the 8 | * Hibernate documentation for the DB2 Dialect. 9 | *

10 | * Created by Karel Maesen,Geovise BVBA on 05/06/17. 11 | */ 12 | 13 | public class Db2WktDecoder extends HANAWktDecoder { 14 | 15 | //DB2 and HANA use the same (E)WKT format, so we just inherit (so later we can substitute a different implementation should the need arise 16 | } 17 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Db2WktEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | /** 4 | * An EWKT encoder for DB2 as used in Hibernate Spatial 5 | *

6 | *

7 | * Note: this Encoder is to be used in combination with the DB2 EWKT transform group created by David Adler. See the 8 | * Hibernate documentation for the DB2 Dialect. 9 | *

10 | * Created by Karel Maesen, Geovise BVBA on 05/06/17. 11 | */ 12 | public class Db2WktEncoder extends HANAWktEncoder { 13 | 14 | //DB2 and HANA use the same (E)WKT format, so we just inherit. 15 | //Later we can substitute a different implementation should the need arise. 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/HANAWkbDialect.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.*; 4 | 5 | class HANAWkbDialect extends WkbDialect { 6 | 7 | final public static HANAWkbDialect INSTANCE = new HANAWkbDialect(); 8 | 9 | private HANAWkbDialect() { 10 | } 11 | 12 | @Override 13 | boolean emptyPointAsNaN() { 14 | return false; 15 | } 16 | 17 | @Override 18 | GeometryType parseType(long tpe) { 19 | return super.parseType((tpe & 0xFFFF) % 100); 20 | } 21 | 22 | protected

int calculateSize(Geometry

geom, boolean includeSrid) { 23 | int size = 1 + ByteBuffer.UINT_SIZE; //size for order byte + type field 24 | if (includeSrid) { 25 | size += 4; 26 | } 27 | if (geom.isEmpty()) return size + ByteBuffer.UINT_SIZE; 28 | return size + geometrySize(geom); 29 | } 30 | 31 | @Override 32 |

BaseWkbVisitor

mkVisitor(Geometry

geom, ByteOrder bo) { 33 | return new HANAWkbVisitor<>(mkByteBuffer(geom, bo), this); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/MySqlWkbDialect.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.AbstractGeometryCollection; 4 | import org.geolatte.geom.ByteBuffer; 5 | import org.geolatte.geom.Geometry; 6 | import org.geolatte.geom.Position; 7 | 8 | class MySqlWkbDialect extends Sfa110WkbDialect { 9 | final public static WkbDialect INSTANCE = new MySqlWkbDialect(); 10 | 11 | @Override 12 | protected

int extraHeaderSize(Geometry

geom) { 13 | return 4; 14 | } 15 | 16 | @Override 17 | protected

int sizeEmptyGeometry(Geometry

geometry) { 18 | return ByteBuffer.UINT_SIZE; 19 | } 20 | 21 | private

boolean hasEmpty(Geometry

geometry) { 22 | if (geometry.isEmpty()) { 23 | return true; 24 | } 25 | if (geometry instanceof AbstractGeometryCollection) { 26 | for (Geometry

part : (AbstractGeometryCollection) geometry) { 27 | if (hasEmpty(part)) return true; 28 | } 29 | } 30 | return false; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/PostgisWkbV2Dialect.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.GeometryType; 5 | import org.geolatte.geom.Position; 6 | 7 | class PostgisWkbV2Dialect extends PostgisWkbV1Dialect { 8 | 9 | final public static PostgisWkbV2Dialect INSTANCE = new PostgisWkbV2Dialect(); 10 | 11 | @Override 12 | boolean emptyPointAsNaN() { 13 | return true; 14 | } 15 | 16 | @Override 17 | protected

Long geometryTypeCode(Geometry

geometry) { 18 | if (geometry.isEmpty() && geometry.getGeometryType() == GeometryType.POINT) { 19 | return (long) WKB_POINT; 20 | } 21 | return super.geometryTypeCode(geometry); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/PostgisWkbV2Encoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | /** 4 | * A Postgis WKB Encoder that encodes empty points as points with NaN coordinates. 5 | * 6 | *

The convention to encode empty points as points with NaN coordinates was 7 | * introduced in Postgis v2.2.2

8 | */ 9 | public class PostgisWkbV2Encoder extends PostgisWkbEncoder { 10 | 11 | public PostgisWkbV2Encoder() { 12 | super(PostgisWkbV2Dialect.INSTANCE); 13 | } 14 | } -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/PostgisWktEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2011 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec; 23 | 24 | import org.geolatte.geom.Geometry; 25 | import org.geolatte.geom.Position; 26 | 27 | /** 28 | * Encodes geometries to Postgis WKT/EWKT representations. 29 | * 30 | * @author Karel Maesen, Geovise BVBA, 2011 31 | */ 32 | public class PostgisWktEncoder implements WktEncoder { 33 | 34 | 35 | @Override 36 | public

String encode(Geometry

geometry) { 37 | return new BaseWktWriter(PostgisWktDialect.INSTANCE, new StringBuilder()).writeGeometry(geometry); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa110WkbDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.ByteBuffer; 4 | import org.geolatte.geom.Geometry; 5 | import org.geolatte.geom.Position; 6 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 7 | 8 | /** 9 | * A WKB decoder for the format specified in Simple Feature Access, version 1.1.0 10 | */ 11 | public class Sfa110WkbDecoder implements WkbDecoder { 12 | 13 | 14 | @Override 15 | public

Geometry

decode(ByteBuffer byteBuffer, CoordinateReferenceSystem

crs) { 16 | BaseWkbParser

parser = new BaseWkbParser<>(Sfa110WkbDialect.INSTANCE, byteBuffer, crs); 17 | try { 18 | return parser.parse(); 19 | } catch( WkbDecodeException e) { 20 | throw e; 21 | } catch (Throwable e) { 22 | throw new WkbDecodeException(e); 23 | } 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa110WkbDialect.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.ByteBuffer; 4 | import org.geolatte.geom.ByteOrder; 5 | import org.geolatte.geom.Geometry; 6 | import org.geolatte.geom.Position; 7 | 8 | class Sfa110WkbDialect extends WkbDialect { 9 | 10 | public final static Sfa110WkbDialect INSTANCE = new Sfa110WkbDialect(); 11 | 12 | protected Sfa110WkbDialect() { 13 | 14 | } 15 | 16 | protected

int getPositionSize(Geometry

geom) { 17 | return 2 * ByteBuffer.DOUBLE_SIZE; 18 | } 19 | 20 | @Override 21 |

BaseWkbVisitor

mkVisitor(Geometry

geom, ByteOrder bo) { 22 | ByteBuffer buffer = mkByteBuffer(geom, bo); 23 | return new SFA110WkbVisitor<>(buffer, this); 24 | } 25 | } 26 | 27 | class SFA110WkbVisitor

extends BaseWkbVisitor

{ 28 | 29 | SFA110WkbVisitor(ByteBuffer byteBuffer, WkbDialect dialect) { 30 | super(byteBuffer, dialect); 31 | } 32 | 33 | @Override 34 | protected void writePoint(double[] coordinates, ByteBuffer output) { 35 | output.putDouble(coordinates[0]); 36 | output.putDouble(coordinates[1]); 37 | } 38 | } -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa110WkbEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.ByteBuffer; 4 | import org.geolatte.geom.ByteOrder; 5 | import org.geolatte.geom.Geometry; 6 | import org.geolatte.geom.Position; 7 | 8 | /** 9 | * A WKB encoder for the format specified in Simple Feature Access, version 1.1.0 10 | */ 11 | public class Sfa110WkbEncoder implements WkbEncoder { 12 | 13 | @Override 14 | public

ByteBuffer encode(Geometry

geometry, ByteOrder byteOrder) { 15 | BaseWkbVisitor

visitor = Sfa110WkbDialect.INSTANCE.mkVisitor(geometry, byteOrder); 16 | geometry.accept(visitor); 17 | return visitor.result(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa110WktDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.Position; 5 | import org.geolatte.geom.codec.support.Holder; 6 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 7 | 8 | public class Sfa110WktDecoder implements WktDecoder { 9 | 10 | @Override 11 | public

Geometry

decode(String wkt, CoordinateReferenceSystem

crs) { 12 | return new Sfa110WktParser<>(wkt, crs).parse(); 13 | } 14 | 15 | } 16 | 17 | class Sfa110WktParser

extends BaseWktParser

{ 18 | 19 | private final static WktDialect dialect = new WktDialect(); 20 | 21 | Sfa110WktParser(String wkt, CoordinateReferenceSystem

crs) { 22 | super(dialect, wkt, crs); 23 | } 24 | 25 | @Override 26 | protected CoordinateReferenceSystem widenCrsToCoordinateDimension(CoordinateReferenceSystem crs) { 27 | //don't do this for this dialect 28 | return crs; 29 | } 30 | 31 | protected Holder matchesMultiPointList() { 32 | return matchesPositionList(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa110WktDialect.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | /** 4 | * A WKT decoder for the format specified in Simple Feature Access, version 1.1.0 5 | */ 6 | class Sfa110WktDialect extends WktDialect { 7 | 8 | public static final Sfa110WktDialect INSTANCE = new Sfa110WktDialect(); 9 | 10 | @Override 11 | boolean writeMultiPointAsListOfPositions() { 12 | return true; 13 | } 14 | 15 | @Override 16 | boolean isLimitedTo2D() { 17 | return true; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa110WktEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.Position; 5 | 6 | /** 7 | * A WKT encoder for the format specified in Simple Feature Access, version 1.1.0 8 | */ 9 | public class Sfa110WktEncoder implements WktEncoder { 10 | 11 | @Override 12 | public

String encode(Geometry

geometry) { 13 | return new Sfa110WktWriter().writeGeometry(geometry); 14 | } 15 | } 16 | 17 | class Sfa110WktWriter extends BaseWktWriter { 18 | 19 | public Sfa110WktWriter() { 20 | super(Sfa110WktDialect.INSTANCE, new StringBuilder()); 21 | } 22 | 23 | @Override 24 | protected

void addMultiPointText(Geometry

geometry) { 25 | addPointList(geometry.getPositions()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa121WkbDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.ByteBuffer; 4 | import org.geolatte.geom.Geometry; 5 | import org.geolatte.geom.Position; 6 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 7 | 8 | /** 9 | * A WKB decoder for the format specified in Simple Feature Access, version 1.2.1 10 | */ 11 | public class Sfa121WkbDecoder implements WkbDecoder { 12 | @Override 13 | public

Geometry

decode(ByteBuffer byteBuffer, CoordinateReferenceSystem

crs) { 14 | BaseWkbParser

parser = new BaseWkbParser<>(Sfa121WkbDialect.INSTANCE, byteBuffer, crs); 15 | try { 16 | return parser.parse(); 17 | } catch( WkbDecodeException e) { 18 | throw e; 19 | } catch (Throwable e) { 20 | throw new WkbDecodeException(e); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa121WkbDialect.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.GeometryType; 5 | import org.geolatte.geom.Position; 6 | 7 | class Sfa121WkbDialect extends WkbDialect { 8 | 9 | final static Sfa121WkbDialect INSTANCE = new Sfa121WkbDialect(); 10 | 11 | @Override 12 | protected

Long geometryTypeCode(Geometry

geometry) { 13 | Long base = super.geometryTypeCode(geometry); 14 | if (geometry.hasZ()) base += 1000L; 15 | if (geometry.hasM()) base += 2000L; 16 | return base; 17 | } 18 | 19 | @Override 20 | GeometryType parseType(long tpe) { 21 | long t = tpe % 1000L; 22 | return super.parseType(t); 23 | } 24 | 25 | @Override 26 | boolean hasZ(long tpe) { 27 | return (tpe > 1000 && tpe < 2000) || tpe > 3000; 28 | } 29 | 30 | @Override 31 | boolean hasM(long tpe) { 32 | return tpe > 2000; 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa121WkbEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.ByteBuffer; 4 | import org.geolatte.geom.ByteOrder; 5 | import org.geolatte.geom.Geometry; 6 | import org.geolatte.geom.Position; 7 | 8 | /** 9 | * A WKB encoder for the format specified in Simple Feature Access, version 1.2.1 10 | */ 11 | public class Sfa121WkbEncoder implements WkbEncoder { 12 | 13 | @Override 14 | public

ByteBuffer encode(Geometry

geometry, ByteOrder byteOrder) { 15 | BaseWkbVisitor

visitor = Sfa121WkbDialect.INSTANCE.mkVisitor(geometry, byteOrder); 16 | geometry.accept(visitor); 17 | return visitor.result(); 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa121WktDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.Position; 5 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 6 | 7 | /** 8 | * A WKT decoder for the format specified in Simple Feature Access, version 1.2.1 9 | */ 10 | public class Sfa121WktDecoder implements WktDecoder { 11 | 12 | @Override 13 | public

Geometry

decode(String wkt, CoordinateReferenceSystem

crs) { 14 | return new Sfa121WktParser<>(wkt, crs).parse(); 15 | } 16 | 17 | } 18 | 19 | class Sfa121WktParser

extends BaseWktParser

{ 20 | 21 | Sfa121WktParser(String wkt, CoordinateReferenceSystem

crs) { 22 | super(Sfa110WktDialect.INSTANCE, wkt, crs); 23 | } 24 | 25 | @Override 26 | protected void matchesOptionalZMMarkers() { 27 | tokenizer.skipWhitespace(); 28 | if (tokenizer.matchesOneOf('Z', 'z').isPresent()) { 29 | this.hasZMark = true; 30 | } 31 | if (tokenizer.matchesOneOf('M', 'm').isPresent()) { 32 | this.hasMMark = true; 33 | } 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa121WktDialect.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.Geometry; 4 | 5 | class Sfa121WktDialect extends WktDialect{ 6 | 7 | final static Sfa121WktDialect INSTANCE = new Sfa121WktDialect(); 8 | 9 | @Override 10 | void addGeometryZMMarker(StringBuilder buffer, Geometry geometry) { 11 | if (!(geometry.hasZ() || geometry.hasM())) return; 12 | 13 | if (geometry.hasZ() && geometry.hasM()) buffer.append(" ZM"); 14 | else if (geometry.hasZ()) buffer.append(" Z"); 15 | else if (geometry.hasM()) buffer.append(" M"); 16 | 17 | if(!geometry.isEmpty()) 18 | buffer.append(' '); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/Sfa121WktEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.Position; 5 | 6 | /** 7 | * A WKT encoder for the format specified in Simple Feature Access, version 1.2.1 8 | */ 9 | public class Sfa121WktEncoder implements WktEncoder { 10 | 11 | @Override 12 | public

String encode(Geometry

geometry) { 13 | return new BaseWktWriter(Sfa121WktDialect.INSTANCE, new StringBuilder()).writeGeometry(geometry); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/UnsupportedConversionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2011 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec; 23 | 24 | /** 25 | * Thrown when the WKT/WKB representation is not supported by the encoder or decoder. 26 | * 27 | * @author Karel Maesen, Geovise BVBA 28 | * creation-date: Nov 12, 2010 29 | */ 30 | public class UnsupportedConversionException extends RuntimeException { 31 | 32 | public UnsupportedConversionException(String msg) { 33 | super(msg); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/WkbDecodeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2012 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec; 23 | 24 | /** 25 | * Thrown when the WKB cannot be parsed. 26 | * 27 | * @author Karel Maesen, Geovise BVBA 28 | */ 29 | public class WkbDecodeException extends RuntimeException { 30 | 31 | WkbDecodeException(String msg) { 32 | super(msg); 33 | } 34 | 35 | WkbDecodeException(Throwable ex) { 36 | super(ex); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/WktDecodeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2011 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec; 23 | 24 | /** 25 | * Thrown when the WKT cannot be parsed (is syntactically incorrect). 26 | * 27 | * @author Karel Maesen, Geovise BVBA, 2011 28 | */ 29 | public class WktDecodeException extends RuntimeException { 30 | 31 | public WktDecodeException(String msg) { 32 | super(msg); 33 | } 34 | 35 | public WktDecodeException(String msg, Throwable cause) { 36 | super(msg, cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/WktEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2012 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec; 23 | 24 | import org.geolatte.geom.Geometry; 25 | import org.geolatte.geom.Position; 26 | 27 | /** 28 | * An Encoder for WKT (Well-Known Text) representations. 29 | *

In general WktEncoder implementations are not be thread-safe.

30 | * 31 | * @author Karel Maesen, Geovise BVBA 32 | */ 33 | public interface WktEncoder { 34 | /** 35 | * Encodes an object to its WKT representation. 36 | * 37 | * @param geometry the Geometry instance to encode 38 | * @return a WKT representation of the specified object. 39 | */ 40 |

String encode(Geometry

geometry); 41 | } 42 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/WktNumberToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2011 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec; 23 | 24 | /** 25 | * A WktToken for numbers. 26 | * 27 | * @author Karel Maesen, Geovise BVBA 28 | * creation-date: 11/19/11 29 | */ 30 | class WktNumberToken implements WktToken { 31 | 32 | private final double number; 33 | 34 | public WktNumberToken(double number) { 35 | super(); 36 | this.number = number; 37 | } 38 | 39 | public double getNumber() { 40 | return number; 41 | } 42 | 43 | public String toString() { 44 | return String.valueOf(number); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/WktPunctuationToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2011 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec; 23 | 24 | /** 25 | * A WktToken that consists of a single char to indicate grouping (list open/close), or 26 | * to delimit values. 27 | * 28 | * @author Karel Maesen, Geovise BVBA 29 | * creation-date: 11/18/11 30 | */ 31 | class WktPunctuationToken implements WktToken { 32 | 33 | private final char punctuationChar; 34 | 35 | public WktPunctuationToken(char c) { 36 | this.punctuationChar = c; 37 | } 38 | 39 | public char getChar() { 40 | return punctuationChar; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return String.valueOf(punctuationChar); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/WktToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2011 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec; 23 | 24 | /** 25 | * A marker interface for tokens in WKT strings. 26 | * 27 | * @author Karel Maesen, Geovise BVBA, 2011 28 | */ 29 | interface WktToken { 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/Decoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2013 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec.db; 23 | 24 | 25 | import org.geolatte.geom.Geometry; 26 | 27 | /** 28 | * Decodes native database objects to geometries of type T. 29 | * 30 | * @param the type of native database object that can be decoded to a {@code Geometry} 31 | * @author Karel Maesen, Geovise BVBA. 32 | */ 33 | public interface Decoder { 34 | 35 | Geometry decode(N nativeGeom); 36 | 37 | boolean accepts(N nativeGeom); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/Encoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2013 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec.db; 23 | 24 | import org.geolatte.geom.Geometry; 25 | import org.geolatte.geom.Position; 26 | 27 | /** 28 | * An {@code Encoder} encodes geometries in instances of type {@code N} 29 | * 30 | * @param the type of encoding result 31 | * @author Karel Maesen, Geovise BVBA. 32 | */ 33 | public interface Encoder { 34 | 35 | 36 |

> N encode(G geom); 37 | 38 |

boolean accepts(Geometry

geom); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/db2/Db2ClobEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.db2; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.Position; 5 | import org.geolatte.geom.codec.Wkt; 6 | import org.geolatte.geom.codec.WktEncoder; 7 | import org.geolatte.geom.codec.db.Encoder; 8 | 9 | /** 10 | * An {@code Encoder} for DB2 as used in Hibernate Spatial 11 | *

12 | * Note: this Encoder is to be used in combination with the DB2 EWKT transform group created by David Adler. See the 13 | * Hibernate documentation for the DB2 Dialect. 14 | *

15 | *

16 | * Created by Karel Maesen, Geovise BVBA on 04/06/17. 17 | */ 18 | public class Db2ClobEncoder implements Encoder { 19 | 20 | @Override 21 | public

> String encode(G geom) { 22 | WktEncoder encoder = Wkt.newEncoder(Wkt.Dialect.DB2_WKT); 23 | return encoder.encode(geom); 24 | } 25 | 26 | @Override 27 | public

boolean accepts(Geometry

geom) { 28 | return false; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/AbstractSDODecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.Position; 5 | import org.geolatte.geom.codec.db.Decoder; 6 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by Karel Maesen, Geovise BVBA on 17/02/15. 12 | */ 13 | abstract public class AbstractSDODecoder implements Decoder { 14 | 15 | protected SDOGeometry nativeGeom; 16 | 17 | @Override 18 | public Geometry decode(SDOGeometry nativeGeom) { 19 | if (!accepts(nativeGeom)) { 20 | throw new IllegalArgumentException(getClass().getSimpleName() + " received object of type " + nativeGeom.getGType()); 21 | } 22 | this.nativeGeom = nativeGeom; 23 | return internalDecode(); 24 | } 25 | 26 | abstract Geometry internalDecode(); 27 | 28 | abstract

Geometry

decode(SDOGType gtype, List elements, CoordinateReferenceSystem

crs); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/Decoders.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.codec.db.Decoder; 5 | 6 | import java.sql.Struct; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 19/03/15. 10 | */ 11 | public class Decoders { 12 | 13 | public static Decoder decoderFor(SDOGeometry object) { 14 | return object.getGType().getTypeGeometry().createDecoder(); 15 | } 16 | 17 | /** 18 | * Decodes the SQL Server Geometry object to its JTS Geometry instance 19 | * 20 | * @param raw 21 | * @return 22 | */ 23 | public static Geometry decode(Struct raw) { 24 | SDOGeometry sdo = SDOGeometry.load(raw); 25 | return decode(sdo); 26 | } 27 | 28 | public static Geometry decode(SDOGeometry sdo) { 29 | Decoder decoder = decoderFor(sdo); 30 | return decoder.decode(sdo); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/Encoders.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.codec.db.Encoder; 5 | 6 | import java.sql.Connection; 7 | import java.sql.SQLException; 8 | import java.sql.Struct; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by Karel Maesen, Geovise BVBA on 01/04/15. 14 | */ 15 | public class Encoders { 16 | 17 | final private static List ENCODERS = new ArrayList(); 18 | 19 | 20 | static { 21 | ENCODERS.add(new PointSdoEncoder()); 22 | ENCODERS.add(new LineStringSdoEncoder()); 23 | ENCODERS.add(new PolygonSdoEncoder()); 24 | ENCODERS.add(new MultiPointSdoEncoder()); 25 | ENCODERS.add(new MultiLineStringSdoEncoder()); 26 | ENCODERS.add(new MultiPolygonSdoEncoder()); 27 | ENCODERS.add(new GeometryCollectionSdoEncoder()); 28 | } 29 | 30 | public static Encoder encoderFor(Geometry geom) { 31 | for (Encoder encoder : ENCODERS) { 32 | if (encoder.accepts(geom)) { 33 | return encoder; 34 | } 35 | } 36 | throw new IllegalArgumentException("No encoder for type " + (geom == null ? "NULL" : geom.getGeometryType())); 37 | } 38 | 39 | public static SDOGeometry encode(Geometry geom) { 40 | Encoder encoder = encoderFor(geom); 41 | return encoder.encode(geom); 42 | } 43 | 44 | public static Struct encode(Geometry geom, Connection conn, SQLTypeFactory typeFactory) throws SQLException { 45 | return typeFactory.createStruct(encode(geom), conn); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/LineStringSdoDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.LineString; 5 | import org.geolatte.geom.Position; 6 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by Karel Maesen, Geovise BVBA on 18/02/15. 12 | */ 13 | public class LineStringSdoDecoder extends AbstractSDODecoder { 14 | 15 | 16 | @Override 17 | public boolean accepts(SDOGeometry nativeGeom) { 18 | return nativeGeom.getGType().getTypeGeometry() == SdoGeometryType.LINE; 19 | } 20 | 21 | @Override 22 | @SuppressWarnings({"unchecked", "rawtypes"}) 23 | protected Geometry internalDecode() { 24 | return decode(nativeGeom.getGType(), nativeGeom.getElements(), nativeGeom.getCoordinateReferenceSystem()); 25 | } 26 | 27 | @SuppressWarnings({"unchecked", "rawtypes"}) 28 | @Override 29 | protected

Geometry

decode(SDOGType gtype, List elements, CoordinateReferenceSystem

crs) { 30 | assert (elements.size() <= 1); 31 | return new LineString(elements.get(0).linearizedPositions(gtype, crs), crs); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/LineStringSdoEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.GeometryType; 5 | import org.geolatte.geom.Position; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 01/04/15. 9 | */ 10 | public class LineStringSdoEncoder extends AbstractSDOEncoder { 11 | @Override 12 | public

boolean accepts(Geometry

geom) { 13 | return GeometryType.LINESTRING.equals(geom.getGeometryType()); 14 | } 15 | 16 | @Override 17 | public

> SDOGeometry encode(G geom) { 18 | final int dim = geom.getCoordinateDimension(); 19 | final int lrsPos = getLRSDim(geom); 20 | final boolean isLrs = lrsPos > 0; 21 | final Double[] ordinates = convertPositionSequence(geom.getPositions()); 22 | final ElemInfo info = new ElemInfo(1); 23 | info.setElement(0, 1, ElementType.LINE_STRAIGTH_SEGMENTS); 24 | return new SDOGeometry( 25 | new SDOGType(dim, lrsPos, SdoGeometryType.LINE), 26 | geom.getSRID(), 27 | null, 28 | info, 29 | new Ordinates(ordinates)); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/MultiLineSdoDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.LineString; 5 | import org.geolatte.geom.MultiLineString; 6 | import org.geolatte.geom.Position; 7 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 8 | 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | 12 | /** 13 | * Created by Karel Maesen, Geovise BVBA on 19/03/15. 14 | */ 15 | public class MultiLineSdoDecoder extends AbstractSDODecoder { 16 | 17 | @Override 18 | public boolean accepts(SDOGeometry nativeGeom) { 19 | return nativeGeom.getGType().getTypeGeometry() == SdoGeometryType.MULTILINE; 20 | } 21 | 22 | @Override 23 | @SuppressWarnings("unchecked") 24 | Geometry internalDecode() { 25 | return decode(nativeGeom.getGType(), nativeGeom.getElements(), nativeGeom.getCoordinateReferenceSystem()); 26 | } 27 | 28 | @SuppressWarnings("unchecked") 29 | @Override 30 | protected

Geometry

decode(SDOGType gtype, List elements, CoordinateReferenceSystem

crs) { 31 | List> strings = elements 32 | .stream() 33 | .map(el -> el.linearizedPositions(gtype, crs)) 34 | .map(ps -> new LineString<>(ps, crs)) 35 | .collect(Collectors.toList()); 36 | return strings.isEmpty() ? new MultiLineString<>(crs) 37 | : new MultiLineString<>(strings.toArray(new LineString[]{})); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/MultiLineStringSdoEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.GeometryType; 5 | import org.geolatte.geom.MultiLineString; 6 | import org.geolatte.geom.Position; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 01/04/15. 10 | */ 11 | public class MultiLineStringSdoEncoder extends AbstractSDOEncoder { 12 | @Override 13 | public

boolean accepts(Geometry

geom) { 14 | return GeometryType.MULTILINESTRING.equals(geom.getGeometryType()); 15 | } 16 | 17 | @Override 18 | @SuppressWarnings("unchecked") 19 | public

> SDOGeometry encode(G geom) { 20 | MultiLineString

multiLineString = (MultiLineString

) geom; 21 | final int dim = multiLineString.getCoordinateDimension(); 22 | final int lrsDim = getLRSDim(multiLineString); 23 | final boolean isLrs = (lrsDim != 0); 24 | 25 | SDOGType sdoGtype = new SDOGType(dim, lrsDim, SdoGeometryType.MULTILINE); 26 | 27 | final ElemInfo info = new ElemInfo(multiLineString.getNumGeometries()); 28 | int oordinatesOffset = 1; 29 | Double[] ordinates = new Double[]{}; 30 | for (int i = 0; i < multiLineString.getNumGeometries(); i++) { 31 | info.setElement(i, oordinatesOffset, ElementType.LINE_STRAIGTH_SEGMENTS); 32 | ordinates = addOrdinates(ordinates, convertPositionSequence(multiLineString.getGeometryN(i).getPositions())); 33 | oordinatesOffset = ordinates.length + 1; 34 | } 35 | return new SDOGeometry(sdoGtype, geom.getSRID(), null, info, new Ordinates(ordinates)); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/MultiPointSdoDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.MultiPoint; 5 | import org.geolatte.geom.Point; 6 | import org.geolatte.geom.Position; 7 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by Karel Maesen, Geovise BVBA on 19/03/15. 13 | */ 14 | public class MultiPointSdoDecoder extends AbstractSDODecoder { 15 | 16 | @Override 17 | public boolean accepts(SDOGeometry nativeGeom) { 18 | return nativeGeom.getGType().getTypeGeometry() == SdoGeometryType.MULTIPOINT; 19 | } 20 | 21 | @Override 22 | @SuppressWarnings("unchecked") 23 | Geometry internalDecode() { 24 | return decode(nativeGeom.getGType(), nativeGeom.getElements() 25 | , nativeGeom.getCoordinateReferenceSystem()); 26 | } 27 | 28 | @SuppressWarnings({"rawtypes", "unchecked"}) 29 | @Override 30 | protected

Geometry

decode(SDOGType gtype, List elements, CoordinateReferenceSystem

crs) { 31 | Point[] pnts = elements.stream() 32 | .map(el -> el.linearizedPositions(gtype, crs)) 33 | .flatMap(pos -> pos.stream().map(p -> new Point(p, crs))) 34 | .toArray(Point[]::new); 35 | return pnts.length > 0 ? new MultiPoint(pnts) : new MultiPoint(crs); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/MultiPolygonSdoDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.*; 4 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by Karel Maesen, Geovise BVBA on 19/03/15. 11 | */ 12 | public class MultiPolygonSdoDecoder extends AbstractSDODecoder { 13 | 14 | @Override 15 | public boolean accepts(SDOGeometry nativeGeom) { 16 | return nativeGeom.getGType().getTypeGeometry() == SdoGeometryType.MULTIPOLYGON; 17 | } 18 | 19 | @Override 20 | @SuppressWarnings("unchecked") 21 | Geometry internalDecode() { 22 | return decode(nativeGeom.getGType(), nativeGeom.getElements(), nativeGeom.getCoordinateReferenceSystem()); 23 | } 24 | 25 | @Override 26 | protected

Geometry

decode(SDOGType gtype, List elements, CoordinateReferenceSystem

crs) { 27 | List> polys = new ArrayList<>(); 28 | List rings = new ArrayList<>(); 29 | AbstractSDODecoder decoder = new PolygonSdoDecoder(); 30 | for (Element element : elements) { 31 | if (element.isExteriorRing() && !rings.isEmpty()) { 32 | polys.add((Polygon

)decoder.decode(gtype, rings, crs)); 33 | rings.clear(); 34 | } 35 | rings.add(element); 36 | } 37 | if (!rings.isEmpty()) { 38 | polys.add((Polygon

)decoder.decode(gtype, rings, crs)); 39 | } 40 | return polys.isEmpty() ? 41 | new MultiPolygon<>(crs) : 42 | new MultiPolygon<>(polys.toArray(new Polygon[0])); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/MultiPolygonSdoEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.*; 4 | 5 | /** 6 | * Created by Karel Maesen, Geovise BVBA on 01/04/15. 7 | */ 8 | public class MultiPolygonSdoEncoder extends AbstractSDOEncoder { 9 | @Override 10 | public

boolean accepts(Geometry

geom) { 11 | return GeometryType.MULTIPOLYGON.equals(geom.getGeometryType()); 12 | } 13 | 14 | @Override 15 | @SuppressWarnings("unchecked") 16 | public

> SDOGeometry encode(G geom) { 17 | MultiPolygon

multiPolygon = (MultiPolygon

) geom; 18 | final int dim = multiPolygon.getCoordinateDimension(); 19 | final int lrsPos = getLRSDim(multiPolygon); 20 | 21 | SDOGType gType = new SDOGType(dim, lrsPos, SdoGeometryType.MULTIPOLYGON); 22 | SDOGeometry sdoGeom = new SDOGeometry(gType, geom.getSRID(), null, null, null); 23 | for (int i = 0; i < multiPolygon.getNumGeometries(); i++) { 24 | try { 25 | final Polygon

pg = multiPolygon.getGeometryN(i); 26 | sdoGeom = addPolygon(sdoGeom, pg); 27 | } catch (Exception e) { 28 | throw new RuntimeException("Found geometry that was not a geometry in MultiPolygon", e); 29 | } 30 | } 31 | return sdoGeom; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/PointSdoEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.GeometryType; 5 | import org.geolatte.geom.Position; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 01/04/15. 9 | */ 10 | public class PointSdoEncoder extends AbstractSDOEncoder { 11 | 12 | @Override 13 | public

boolean accepts(Geometry

geom) { 14 | return GeometryType.POINT.equals(geom.getGeometryType()); 15 | } 16 | 17 | @Override 18 | public

> SDOGeometry encode(G geom) { 19 | final int dim = geom.getCoordinateDimension(); 20 | final int lrsDim = getLRSDim(geom); 21 | final boolean isLrs = (lrsDim != 0); 22 | 23 | final Double[] coord = convertPositionSequence(geom.getPositions()); 24 | 25 | if (Settings.useSdoPointType() && !isLrs && !geom.isEmpty()) { 26 | return new SDOGeometry( 27 | new SDOGType(dim, lrsDim, SdoGeometryType.POINT), 28 | geom.getSRID(), 29 | new SDOPoint(coord), null, null 30 | ); 31 | } 32 | 33 | final ElemInfo info = new ElemInfo(1); 34 | info.setElement(0, 1, ElementType.POINT); 35 | return new SDOGeometry( 36 | new SDOGType(dim, lrsDim, SdoGeometryType.POINT), 37 | geom.getSRID(), 38 | null, 39 | info, 40 | new Ordinates(coord) 41 | ); 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/PolygonSdoEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.GeometryType; 5 | import org.geolatte.geom.Polygon; 6 | import org.geolatte.geom.Position; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 01/04/15. 10 | */ 11 | public class PolygonSdoEncoder extends AbstractSDOEncoder { 12 | @Override 13 | public

boolean accepts(Geometry

geom) { 14 | return GeometryType.POLYGON.equals(geom.getGeometryType()); 15 | } 16 | 17 | @Override 18 | public

> SDOGeometry encode(G geom) { 19 | final int dim = geom.getCoordinateDimension(); 20 | final int lrsPos = getLRSDim(geom); 21 | 22 | SDOGType sdogType = new SDOGType(dim, lrsPos, SdoGeometryType.POLYGON); 23 | SDOGeometry base = new SDOGeometry(sdogType, geom.getSRID(), null, null, null); 24 | Polygon polygon = (Polygon) geom; 25 | return addPolygon(base, polygon); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/oracle/Settings.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 04/12/16. 5 | */ 6 | public class Settings { 7 | 8 | final public static String USE_SDO_POINT = "GEOLATTE_USE_SDO_POINT_TYPE"; 9 | 10 | 11 | public static boolean useSdoPointType() { 12 | String use = System.getProperty(USE_SDO_POINT); 13 | return determineValue(use); 14 | } 15 | 16 | private static boolean determineValue(String val) { 17 | if (val == null) return false; 18 | return val.equalsIgnoreCase("true") || val.equalsIgnoreCase("1"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/sqlserver/IndexRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2013 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec.db.sqlserver; 23 | 24 | /** 25 | * A Range of indices. 26 | */ 27 | class IndexRange { 28 | 29 | final int start; 30 | final int end; 31 | 32 | IndexRange(int start, int end) { 33 | this.start = start; 34 | this.end = end; 35 | } 36 | 37 | int length() { 38 | return this.end - this.start; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/sqlserver/MultiLineStringSqlServerDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2013 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec.db.sqlserver; 23 | 24 | import org.geolatte.geom.MultiLineString; 25 | 26 | import java.util.List; 27 | 28 | import static org.geolatte.geom.Geometries.mkMultiLineString; 29 | 30 | 31 | class MultiLineStringSqlServerDecoder extends AbstractGeometryCollectionSqlServerDecoder { 32 | 33 | @Override 34 | protected OpenGisType getOpenGisType() { 35 | return OpenGisType.MULTILINESTRING; 36 | } 37 | 38 | @Override 39 | protected MultiLineString createGeometry(List geometries, SqlServerGeometry nativeGeom) { 40 | return mkMultiLineString(geometries); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/sqlserver/MultiPolygonSqlServerDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2013 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec.db.sqlserver; 23 | 24 | import org.geolatte.geom.MultiPolygon; 25 | 26 | import java.util.List; 27 | 28 | import static org.geolatte.geom.Geometries.mkMultiPolygon; 29 | 30 | class MultiPolygonSqlServerDecoder extends AbstractGeometryCollectionSqlServerDecoder { 31 | 32 | @Override 33 | protected OpenGisType getOpenGisType() { 34 | return OpenGisType.MULTIPOLYGON; 35 | } 36 | 37 | @Override 38 | protected MultiPolygon createGeometry(List geometries, SqlServerGeometry nativeGeom) { 39 | return mkMultiPolygon(geometries); 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/db/sqlserver/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Encoder/Decoder classes for serializing Geometries and Coordinate Reference Systems to Microsoft SQL Server internal 3 | * format. 4 | *

5 | * Created by maesenka on 07/10/14. 6 | */ 7 | package org.geolatte.geom.codec.db.sqlserver; -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Encoder/Decoder classes for serializing Geometries and Coordinate Reference Systems. 3 | *

4 | * Created by maesenka on 07/10/14. 5 | */ 6 | package org.geolatte.geom.codec; -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/support/CollectionGeometryBuilder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.support; 2 | 3 | import org.geolatte.geom.Geometries; 4 | import org.geolatte.geom.Geometry; 5 | import org.geolatte.geom.GeometryType; 6 | import org.geolatte.geom.Position; 7 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.stream.Collectors; 12 | 13 | public class CollectionGeometryBuilder extends GeometryBuilder { 14 | final private List components = new ArrayList<>(); 15 | 16 | public void push(GeometryBuilder builder) { 17 | components.add(builder); 18 | } 19 | 20 | public

Geometry

createGeometry(CoordinateReferenceSystem

crs) { 21 | if (components.isEmpty()) return Geometries.mkEmptyGeometry(GeometryType.GEOMETRYCOLLECTION, crs); 22 | List> geoms = components.stream() 23 | .map(c -> c.createGeometry(crs)) 24 | .collect(Collectors.toList()); 25 | return Geometries.mkGeometryCollection(geoms); 26 | } 27 | 28 | @Override 29 | public int getCoordinateDimension() { 30 | return components.isEmpty() ? 2 : components.get(0).getCoordinateDimension(); 31 | } 32 | 33 | @Override 34 | public void setPositions(Holder positions) { 35 | throw new IllegalStateException("Can't set positions directly on this instance"); 36 | } 37 | 38 | @Override 39 | public boolean isEmpty() { 40 | return this.components.isEmpty(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/support/DecodeException.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.support; 2 | 3 | public class DecodeException extends RuntimeException { 4 | 5 | public DecodeException(String msg) { 6 | super(msg); 7 | } 8 | 9 | public DecodeException(String msg, Throwable t) { 10 | super(msg, t); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/support/GeometryBuilder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.support; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.GeometryType; 5 | import org.geolatte.geom.Position; 6 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 7 | 8 | abstract public class GeometryBuilder { 9 | public static GeometryBuilder create(GeometryType type) { 10 | if (type == GeometryType.GEOMETRYCOLLECTION) { 11 | return new CollectionGeometryBuilder(); 12 | } else { 13 | return new SimpleGeometryBuilder(type); 14 | } 15 | } 16 | 17 | abstract public

Geometry

createGeometry(CoordinateReferenceSystem

crs); 18 | 19 | abstract public int getCoordinateDimension(); 20 | 21 | abstract public void setPositions(Holder positions); 22 | 23 | abstract public boolean isEmpty(); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/support/Holder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.support; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.GeometryType; 5 | import org.geolatte.geom.Position; 6 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 09/09/17. 10 | */ 11 | abstract public class Holder { 12 | 13 | abstract public boolean isEmpty(); 14 | 15 | abstract public int getCoordinateDimension(); 16 | 17 | abstract public

Geometry

toGeometry(CoordinateReferenceSystem

crs, GeometryType geomType); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/support/PolygonListHolder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.support; 2 | 3 | import org.geolatte.geom.*; 4 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.stream.Collectors; 9 | 10 | /** 11 | * Created by Karel Maesen, Geovise BVBA on 11/09/17. 12 | */ 13 | public class PolygonListHolder extends Holder { 14 | 15 | final private List spcs = new ArrayList<>(); 16 | 17 | public void push(LinearPositionsListHolder lph) { 18 | spcs.add(lph); 19 | } 20 | 21 | @Override 22 | public boolean isEmpty() { 23 | return spcs.isEmpty(); 24 | } 25 | 26 | @Override 27 | public int getCoordinateDimension() { 28 | return spcs.stream().mapToInt(Holder::getCoordinateDimension).max().orElse(0); 29 | } 30 | 31 | @Override 32 | public

Geometry

toGeometry(CoordinateReferenceSystem

crs, GeometryType geomType) { 33 | return isEmpty() ? Geometries.mkEmptyMultiPolygon(crs) : Geometries.mkMultiPolygon(toPolygons(crs)); 34 | } 35 | 36 |

List> toPolygons(CoordinateReferenceSystem

crs) { 37 | return spcs.stream().map(lph -> 38 | lph.isEmpty() ? Geometries.mkEmptyPolygon(crs) : Geometries.mkPolygon(lph.toLinearRings(crs)) 39 | ).collect(Collectors.toList()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/support/SimpleGeometryBuilder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.support; 2 | 3 | import org.geolatte.geom.Geometries; 4 | import org.geolatte.geom.Geometry; 5 | import org.geolatte.geom.GeometryType; 6 | import org.geolatte.geom.Position; 7 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 8 | 9 | public class SimpleGeometryBuilder extends GeometryBuilder { 10 | final private GeometryType type; 11 | private Holder positions; 12 | 13 | public SimpleGeometryBuilder(GeometryType type) { 14 | this.type = type; 15 | } 16 | 17 | public

Geometry

createGeometry(CoordinateReferenceSystem

crs) { 18 | if (positions == null || positions.isEmpty()) return Geometries.mkEmptyGeometry(type, crs); 19 | return positions.toGeometry(crs, type); 20 | } 21 | 22 | @Override 23 | public int getCoordinateDimension() { 24 | return positions == null || positions.isEmpty() ? 2 : positions.getCoordinateDimension(); 25 | } 26 | 27 | @Override 28 | public void setPositions(Holder positions) { 29 | this.positions = positions; 30 | } 31 | 32 | @Override 33 | public boolean isEmpty() { 34 | return positions == null || positions.isEmpty(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/codec/support/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package contains data structures useful when decoding {@code Geometry}s from WKT/WKB or GEOJSON 3 | */ 4 | package org.geolatte.geom.codec.support; -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/AngularUnit.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * Angular units 5 | * 6 | * Created by Karel Maesen, Geovise BVBA on 28/11/14. 7 | */ 8 | public class AngularUnit extends Unit { 9 | 10 | /** 11 | * Creates an instance. 12 | * 13 | * @param crsId 14 | * @param name 15 | * @param conversionFactor 16 | */ 17 | public AngularUnit(CrsId crsId, String name, double conversionFactor) { 18 | super(crsId, name, conversionFactor); 19 | } 20 | 21 | @Override 22 | public AngularUnit getFundamentalUnit() { 23 | return Unit.RADIAN; 24 | } 25 | 26 | @Override 27 | public boolean isAngular() { 28 | return true; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/CartesianCoordinateSystem3DM.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | import org.geolatte.geom.C3DM; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 28/11/14. 10 | */ 11 | public class CartesianCoordinateSystem3DM extends CoordinateSystem { 12 | 13 | private final static List REQUIRED_AXIS_NORMAL_ORDER = Arrays.asList(0, 1, 2, 3); 14 | 15 | public CartesianCoordinateSystem3DM(StraightLineAxis firstAxis, StraightLineAxis secondAxis, VerticalStraightLineAxis 16 | thirdAxis, MeasureStraightLineAxis fourthAxis) { 17 | super(firstAxis, secondAxis, thirdAxis, fourthAxis); 18 | checkAxes(); 19 | } 20 | 21 | private void checkAxes() { 22 | List order = getAxisNormalOrder(); 23 | if (!order.containsAll(REQUIRED_AXIS_NORMAL_ORDER)) { 24 | throw new IllegalArgumentException("Require order 0, 1, 2 and 3 axes"); 25 | } 26 | } 27 | 28 | @Override 29 | public Class getPositionClass() { 30 | return C3DM.class; 31 | } 32 | 33 | @Override 34 | public CoordinateSystem merge(OneDimensionCoordinateSystem coordinateSystem) { 35 | throw new UnsupportedOperationException(); 36 | } 37 | 38 | @Override 39 | public CoordinateSystem extend(CoordinateSystemAxis axis) { 40 | throw new UnsupportedOperationException(); 41 | } 42 | 43 | @Override 44 | public boolean hasZ() { 45 | return true; 46 | } 47 | 48 | @Override 49 | public boolean hasM() { 50 | return true; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/CrsExtendedId.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | import java.util.Objects; 4 | 5 | /** 6 | * Created by Karel Maesen, Geovise BVBA on 11/09/2018. 7 | */ 8 | public class CrsExtendedId extends CrsId { 9 | 10 | final private Unit verticalUnit; 11 | final private Unit measureUnit; 12 | 13 | /** 14 | * Creates an instance having the specified authority and code. 15 | * 16 | *

If authority EPSG and 0 or -1 is passed for the code parameter, a value equal to CrsId.UNDEFINED is returned. 17 | * 18 | * param base base CrsId 19 | * @return a CrsId for the specified authority and code. 20 | */ 21 | CrsExtendedId(CrsId base, Unit verticalUnit, Unit measureUnit) { 22 | super(base.getAuthority(), base.getCode()); 23 | this.verticalUnit = verticalUnit; 24 | this.measureUnit = measureUnit; 25 | } 26 | 27 | @Override 28 | public boolean equals(Object o) { 29 | if (this == o) return true; 30 | if (o == null || getClass() != o.getClass()) return false; 31 | if (!super.equals(o)) return false; 32 | CrsExtendedId that = (CrsExtendedId) o; 33 | return Objects.equals(verticalUnit, that.verticalUnit) && 34 | Objects.equals(measureUnit, that.measureUnit); 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return Objects.hash(super.hashCode(), verticalUnit, measureUnit); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/EllipsoidalAxis.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 28/11/14. 5 | */ 6 | abstract public class EllipsoidalAxis extends CoordinateSystemAxis { 7 | 8 | 9 | EllipsoidalAxis(String axisName, CoordinateSystemAxisDirection coordinateSystemAxisDirection, Unit unit) { 10 | super(axisName, coordinateSystemAxisDirection, unit); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/EllipsoidalCoordinateSystem3DM.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | import org.geolatte.geom.G3DM; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 28/11/14. 10 | */ 11 | public class EllipsoidalCoordinateSystem3DM extends CoordinateSystem { 12 | 13 | private final static List REQUIRED_AXIS_NORMAL_ORDER = Arrays.asList(0, 1, 2, 3); 14 | 15 | public EllipsoidalCoordinateSystem3DM(EllipsoidalAxis first, EllipsoidalAxis second, StraightLineAxis heightAxis, 16 | MeasureStraightLineAxis other) { 17 | super(first, second, heightAxis, other); 18 | checkAxes(); 19 | } 20 | 21 | private void checkAxes() { 22 | List order = getAxisNormalOrder(); 23 | if (!order.containsAll(REQUIRED_AXIS_NORMAL_ORDER)) { 24 | throw new IllegalArgumentException("Require order 0, 1, 2 and 3 axes"); 25 | } 26 | } 27 | 28 | @Override 29 | public Class getPositionClass() { 30 | return G3DM.class; 31 | } 32 | 33 | @Override 34 | public CoordinateSystem merge(OneDimensionCoordinateSystem coordinateSystem) { 35 | throw new UnsupportedOperationException(); 36 | } 37 | 38 | @Override 39 | public CoordinateSystem extend(CoordinateSystemAxis axis) { 40 | throw new UnsupportedOperationException(); 41 | } 42 | 43 | @Override 44 | public boolean hasZ() { 45 | return true; 46 | } 47 | 48 | @Override 49 | public boolean hasM() { 50 | return true; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/EllipsoidalHeightCSAXis.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * A coordinate system axis for ellipsoidal height, defined as the distance of a point from the ellipsoid measured along 5 | * the perpendicular from the ellipsoid to this point, positive if upwards or outside of the ellipsoid 6 | * 7 | * Created by Karel Maesen, Geovise BVBA on 28/11/14. 8 | */ 9 | public class EllipsoidalHeightCSAXis extends StraightLineAxis { 10 | 11 | /** 12 | * Creates an instance. 13 | * 14 | * @param axisName the name for this axis 15 | * @param unit the unit of this axis 16 | */ 17 | EllipsoidalHeightCSAXis(String axisName, LinearUnit unit) { 18 | super(axisName, CoordinateSystemAxisDirection.UP, unit); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/Extension.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by Karel Maesen, Geovise BVBA on 23/04/16. 7 | */ 8 | public class Extension implements Serializable { 9 | 10 | private static final long serialVersionUID = 6884205871950410216L; 11 | 12 | private final String name; 13 | private final String value; 14 | 15 | public Extension(String name, String value) { 16 | this.name = name; 17 | this.value = value; 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public String getValue() { 25 | return value; 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/GeodeticLatitudeCSAxis.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * A coordinate system axis for geodetic latitude, defined as the angle from the equatorial plane to the perpendicular 5 | * to the ellipsoid through a given point, northwards treated as positive 6 | * 7 | * Created by Karel Maesen, Geovise BVBA on 28/11/14. 8 | */ 9 | public class GeodeticLatitudeCSAxis extends EllipsoidalAxis { 10 | 11 | /** 12 | * Creates an instance. 13 | * 14 | * @param axisName the name for this axis 15 | * @param unit the unit of this axis 16 | */ 17 | public GeodeticLatitudeCSAxis(String axisName, AngularUnit unit) { 18 | super(axisName, CoordinateSystemAxisDirection.NORTH, unit); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/GeodeticLongitudeCSAxis.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * A coordinate system axis for geodetic longitude, defined as the angle from the prime meridian plane to the meridian 5 | * plane of a given point, eastward treated as positive 6 | * 7 | * Created by Karel Maesen, Geovise BVBA on 28/11/14. 8 | */ 9 | public class GeodeticLongitudeCSAxis extends EllipsoidalAxis { 10 | 11 | /** 12 | * Creates an instance. 13 | * 14 | * @param axisName the name for this axis 15 | * @param unit the unit of this axis 16 | */ 17 | public GeodeticLongitudeCSAxis(String axisName, AngularUnit unit) { 18 | super(axisName, CoordinateSystemAxisDirection.EAST, unit); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/Geographic3DCoordinateReferenceSystem.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | import org.geolatte.geom.G3D; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 30/11/14. 10 | */ 11 | public class Geographic3DCoordinateReferenceSystem extends GeographicCoordinateReferenceSystem { 12 | 13 | 14 | 15 | /** 16 | * Constructs a 3-Dimensional geographic coordinate reference system. 17 | * 18 | * @param crsId the {@link org.geolatte.geom.crs.CrsId} that identifies this 19 | * CoordinateReferenceSystem uniquely 20 | * @param name the commonly used name for this CoordinateReferenceSystem 21 | * @param coordinateSystem the coordinate system to use @throws java.lang.IllegalArgumentException if less than 22 | * two {@link org.geolatte.geom.crs.CoordinateSystemAxis CoordinateSystemAxes} are passed. 23 | */ 24 | public Geographic3DCoordinateReferenceSystem(CrsId crsId, String name, EllipsoidalCoordinateSystem3D coordinateSystem) { 25 | super(crsId, name, coordinateSystem); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/InconsistentCoordinateSystemException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2014 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.crs; 23 | 24 | /** 25 | * @author Karel Maesen, Geovise BVBA 26 | * creation-date: 5/16/14 27 | */ 28 | public class InconsistentCoordinateSystemException extends RuntimeException { 29 | 30 | public InconsistentCoordinateSystemException(String msg) { 31 | super(msg); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/LinearCoordinateReferenceSystem.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | import org.geolatte.geom.M; 4 | 5 | /** 6 | * A 1-Dimensional Linear Coordinate Ssytem that consists of the points that lie on the axis of a linear 7 | * feature, for example a pipeline or a road. 8 | * 9 | * Created by Karel Maesen, Geovise BVBA on 29/11/14. 10 | */ 11 | public class LinearCoordinateReferenceSystem extends SingleCoordinateReferenceSystem implements OneDimensionCoordinateReferenceSystem { 12 | 13 | public LinearCoordinateReferenceSystem(String name, MeasureStraightLineAxis axis) { 14 | super(CrsId.UNDEFINED, name, new OneDimensionCoordinateSystem(axis, M.class)); 15 | } 16 | 17 | public MeasureStraightLineAxis getLinearAxis(){ 18 | return (MeasureStraightLineAxis)getCoordinateSystem().getAxis(0); 19 | } 20 | 21 | @Override 22 | public CoordinateSystemAxis getStraightLineAxis() { 23 | return getLinearAxis(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/LinearUnit.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 28/11/14. 5 | */ 6 | public class LinearUnit extends Unit { 7 | /** 8 | * Creates an instance. 9 | * 10 | * @param crsId 11 | * @param name 12 | * @param conversionFactor 13 | */ 14 | public LinearUnit(CrsId crsId, String name, double conversionFactor) { 15 | super(crsId, name, conversionFactor); 16 | } 17 | 18 | @Override 19 | public LinearUnit getFundamentalUnit() { 20 | return Unit.METER; 21 | } 22 | 23 | @Override 24 | public boolean isAngular() { 25 | return false; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/MeasureStraightLineAxis.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * An axis for a {@code LinearCoordinateReferenceSystem} 5 | * 6 | * Created by Karel Maesen, Geovise BVBA on 29/11/14. 7 | */ 8 | public class MeasureStraightLineAxis extends StraightLineAxis { 9 | 10 | /** 11 | * Creates an instance. 12 | * 13 | * @param axisName the name for this axis 14 | * @param unit the unit of this axis 15 | */ 16 | public MeasureStraightLineAxis(String axisName, LinearUnit unit) { 17 | super(axisName, CoordinateSystemAxisDirection.OTHER, unit); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/OneDimensionCoordinateReferenceSystem.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 2019-03-28. 5 | */ 6 | public interface OneDimensionCoordinateReferenceSystem { 7 | 8 | CoordinateSystemAxis getStraightLineAxis(); 9 | 10 | default Unit getUnit() { 11 | return getStraightLineAxis().getUnit(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/OneDimensionCoordinateSystem.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | import org.geolatte.geom.Position; 4 | 5 | /** 6 | * 7 | * Created by Karel Maesen, Geovise BVBA on 29/11/14. 8 | */ 9 | public class OneDimensionCoordinateSystem

extends CoordinateSystem

{ 10 | 11 | private final Class

posType; 12 | 13 | public OneDimensionCoordinateSystem(StraightLineAxis axis, Class

posType){ 14 | super(axis); 15 | this.posType = posType; 16 | } 17 | 18 | 19 | /** 20 | * Returns the single axis in the coordinate system. 21 | * @return 22 | */ 23 | public CoordinateSystemAxis getAxis() { 24 | return getAxis(0); 25 | } 26 | 27 | @Override 28 | public Class

getPositionClass() { 29 | return posType; 30 | } 31 | 32 | @Override 33 | public CoordinateSystem merge(OneDimensionCoordinateSystem coordinateSystem) { 34 | throw new UnsupportedOperationException(); 35 | } 36 | 37 | @Override 38 | public CoordinateSystem extend(CoordinateSystemAxis axis) { 39 | throw new UnsupportedOperationException(); 40 | } 41 | 42 | @Override 43 | public boolean hasZ() { 44 | return getAxis().getNormalOrder() == 2; 45 | } 46 | 47 | @Override 48 | public boolean hasM() { 49 | return getAxis().getNormalOrder() == 3; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/SingleCoordinateReferenceSystem.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | import org.geolatte.geom.Position; 4 | 5 | /** 6 | * A Coordinate reference system consisting of one Coordinate System and one Datum (as opposed to a Compound CRS) 7 | * 8 | * Created by Karel Maesen, Geovise BVBA on 29/11/14. 9 | */ 10 | abstract public class SingleCoordinateReferenceSystem

extends CoordinateReferenceSystem

{ 11 | 12 | /** 13 | * Constructs a HorizontalCoordinateReferenceSystem. 14 | * 15 | * @param crsId the {@link org.geolatte.geom.crs.CrsId} that identifies this 16 | * CoordinateReferenceSystem uniquely 17 | * @param name the commonly used name for this CoordinateReferenceSystem 18 | * @param coordinateSystem the coordinate system to use @throws java.lang.IllegalArgumentException if less than 19 | * two {@link org.geolatte.geom.crs.CoordinateSystemAxis CoordinateSystemAxes} are passed. 20 | */ 21 | public SingleCoordinateReferenceSystem(CrsId crsId, String name, CoordinateSystem

22 | coordinateSystem) { 23 | super(crsId, name, coordinateSystem); 24 | } 25 | 26 | @Override 27 | public boolean isCompound() { 28 | return false; 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/StraightLineAxis.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * A straight line axis for us in cartesian, vertical or linear coordinate systems 5 | * 6 | * Created by Karel Maesen, Geovise BVBA on 28/11/14. 7 | */ 8 | public class StraightLineAxis extends CoordinateSystemAxis { 9 | /** 10 | * Creates an instance. 11 | * 12 | * @param axisName the name for this axis 13 | * @param coordinateSystemAxisDirection the direction for this axis 14 | * @param unit the unit of this axis 15 | */ 16 | public StraightLineAxis(String axisName, CoordinateSystemAxisDirection coordinateSystemAxisDirection, LinearUnit 17 | unit) { 18 | super(axisName, coordinateSystemAxisDirection, unit); 19 | } 20 | 21 | public StraightLineAxis(String axisName, CoordinateSystemAxisDirection coordinateSystemAxisDirection, int normalOrder, Unit unit) { 22 | super(axisName, coordinateSystemAxisDirection, normalOrder, unit); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/UnsupportedCoordinateReferenceSystem.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 2019-03-24. 5 | */ 6 | public class UnsupportedCoordinateReferenceSystem extends RuntimeException { 7 | 8 | public UnsupportedCoordinateReferenceSystem(CrsId crsId) { 9 | super(String.format("CRS %s is not supported", crsId)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/VerticalCoordinateReferenceSystem.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | import org.geolatte.geom.V; 4 | 5 | /** 6 | * 7 | * Created by Karel Maesen, Geovise BVBA on 29/11/14. 8 | */ 9 | public class VerticalCoordinateReferenceSystem extends SingleCoordinateReferenceSystem implements OneDimensionCoordinateReferenceSystem { 10 | 11 | private final VerticalDatum datum; 12 | 13 | /** 14 | * Constructs an instance. 15 | * 16 | * @param crsId the authority and authority c 17 | * @param name 18 | */ 19 | public VerticalCoordinateReferenceSystem(CrsId crsId, String name, VerticalDatum datum, VerticalStraightLineAxis axis) { 20 | super(crsId, name, new OneDimensionCoordinateSystem(axis, V.class)); 21 | this.datum = datum; 22 | } 23 | 24 | public VerticalDatum getDatum() { 25 | return datum; 26 | } 27 | 28 | public VerticalStraightLineAxis getVerticalAxis() { 29 | return (VerticalStraightLineAxis)getCoordinateSystem().getAxis(0); 30 | } 31 | 32 | public LinearUnit getUnit() { 33 | return getVerticalAxis().getUnit(); 34 | } 35 | 36 | @Override 37 | public CoordinateSystemAxis getStraightLineAxis() { 38 | return getVerticalAxis(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/VerticalDatum.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * Vertical Datum 5 | *

6 | * Determines how elevation is to be interpreted. See this Wikipedia page). 7 | * It is modeled here as in the OGC specification "OpenGIS Implementation Specification: Coordinate Transformation Services" (rev. 1.00)" 8 | *

9 | * Created by Karel Maesen, Geovise BVBA on 29/11/14. 10 | */ 11 | public class VerticalDatum extends CrsIdentifiable { 12 | 13 | public static final VerticalDatum UNKNOWN_VERTICAL_DATUM = new VerticalDatum(CrsId.UNDEFINED, "Undefined " + 14 | "Vertical", 0); 15 | 16 | private final int datumType; 17 | private final Extension extension; 18 | 19 | /** 20 | * Constructs an instance. 21 | * 22 | * @param crsId 23 | * @param name 24 | */ 25 | public VerticalDatum(CrsId crsId, String name, int datumtype) { 26 | this(crsId, name, datumtype, null); 27 | } 28 | 29 | /** 30 | * Constructs an instance 31 | * @param crsId 32 | * @param name 33 | * @param datumtype 34 | */ 35 | public VerticalDatum(CrsId crsId, String name, int datumtype, Extension extension) { 36 | super(crsId, name); 37 | this.datumType = datumtype; 38 | this.extension = extension; 39 | } 40 | 41 | public int getDatumType() { 42 | return this.datumType; 43 | } 44 | 45 | public Extension getExtension() { 46 | return this.extension; 47 | } 48 | 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/VerticalStraightLineAxis.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 29/11/14. 5 | */ 6 | public class VerticalStraightLineAxis extends StraightLineAxis { 7 | /** 8 | * Creates an instance. 9 | * 10 | * @param axisName the name for this axis 11 | * @param unit the unit of this axis 12 | */ 13 | public VerticalStraightLineAxis(String axisName, LinearUnit unit) { 14 | super(axisName, CoordinateSystemAxisDirection.UP, unit); 15 | } 16 | 17 | public VerticalStraightLineAxis(String axisName, CoordinateSystemAxisDirection coordinateSystemAxisDirection, LinearUnit unit) { 18 | super(axisName, coordinateSystemAxisDirection, unit); 19 | if (coordinateSystemAxisDirection.defaultNormalOrder != 2) 20 | throw new IllegalArgumentException("Only UP and DOWN directions allowed"); 21 | } 22 | 23 | @Override 24 | public LinearUnit getUnit() { 25 | return (LinearUnit)super.getUnit(); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/package.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | This package contains classes that model Coordinate Reference Systems. The model is based on the 9 | "OpenGIS Implementation Specification: Coordinate Transformation Services" (rev. 1.00). This document 10 | is referred to as [CTS-1.00]. 11 | 12 | The Coordinate Reference Systems determine the interpretation in 2D of the {@code Coordinate}s. 13 | 14 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/trans/CoordinateOperation.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs.trans; 2 | 3 | /** 4 | * Low-level transformation interface 5 | * 6 | * Created by Karel Maesen, Geovise BVBA on 20/07/17. 7 | */ 8 | public interface CoordinateOperation { 9 | 10 | boolean isReversible(); 11 | 12 | int inCoordinateDimension(); 13 | 14 | int outCoordinateDimension(); 15 | 16 | void forward(double[] inCoordinate, double[] outCoordinate); 17 | 18 | void reverse(double[] inCoordinate, double[] outCoordinate); 19 | 20 | /** 21 | * Creates a new {@code CoordinateOperation} from this instance by appending and the specified instance in the forward direction; 22 | * 23 | * @param operation the instance to append 24 | * @return a new instance 25 | */ 26 | default CoordinateOperation appendForward(CoordinateOperation operation) { 27 | return new ConcatenatedOperation.Builder().forward( this ).forward(operation).build(); 28 | } 29 | 30 | /** 31 | * Creates a new {@code CoordinateOperation} from this instance by appending and the specified instance in the reverse direction; 32 | * 33 | * @param operation the instance to append 34 | * @return a new instance 35 | */ 36 | default CoordinateOperation appendReverse(CoordinateOperation operation) { 37 | return new ConcatenatedOperation.Builder().forward( this ).reverse(operation).build(); 38 | } 39 | 40 | 41 | /** 42 | * Creates a new {@code CoordinateOperation} by reversing this instance 43 | * @return a new {@code CoordinateOperation} by reversing this instance 44 | */ 45 | default CoordinateOperation reversed() { 46 | return new ConcatenatedOperation.Builder().reverse(this).build(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/trans/EnvelopeTransform.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs.trans; 2 | 3 | import org.geolatte.geom.Envelope; 4 | import org.geolatte.geom.Position; 5 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 2019-03-28. 9 | */ 10 | public class EnvelopeTransform

{ 11 | 12 | final private TransformOperation operation; 13 | 14 | public EnvelopeTransform(TransformOperation operation) { 15 | this.operation = operation; 16 | 17 | } 18 | 19 | public Envelope forward(Envelope

envelope) { 20 | P ll = envelope.lowerLeft(); 21 | P ur = envelope.upperRight(); 22 | Q tll = operation.forward(ll); 23 | Q tur = operation.forward(ur); 24 | return new Envelope<>(tll, tur, operation.getTarget()); 25 | } 26 | 27 | public Envelope

reverse(Envelope envelope) { 28 | Q ll = envelope.lowerLeft(); 29 | Q ur = envelope.upperRight(); 30 | P tll = operation.reverse(ll); 31 | P tur = operation.reverse(ur); 32 | return new Envelope<>(tll, tur, operation.getSource()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/trans/Geographic3DTo2DConversion.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs.trans; 2 | 3 | /** 4 | * Converts between a Geographic 3D and a 2D system 5 | * 6 | * EPSG Method 9659 7 | * Created by Karel Maesen, Geovise BVBA on 20/07/17. 8 | */ 9 | public class Geographic3DTo2DConversion implements CoordinateOperation, WithEpsgGOperationMethod { 10 | 11 | final private double height; 12 | 13 | public Geographic3DTo2DConversion(double height) { 14 | this.height = height; 15 | } 16 | 17 | 18 | public Geographic3DTo2DConversion() { 19 | this(0.0d); 20 | } 21 | 22 | @Override 23 | public boolean isReversible() { 24 | return true; 25 | } 26 | 27 | @Override 28 | public int inCoordinateDimension() { 29 | return 3; 30 | } 31 | 32 | @Override 33 | public int outCoordinateDimension() { 34 | return 2; 35 | } 36 | 37 | @Override 38 | public void forward(double[] inCoordinate, double[] outCoordinate) { 39 | System.arraycopy(inCoordinate, 0, outCoordinate, 0, 2); 40 | } 41 | 42 | @Override 43 | public void reverse(double[] inCoordinate, double[] outCoordinate) { 44 | System.arraycopy(inCoordinate, 0, outCoordinate, 0, 2); 45 | outCoordinate[2] = height; 46 | } 47 | 48 | @Override 49 | public int getMethodId() { 50 | return 9659; 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/trans/TransformOperation.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs.trans; 2 | 3 | import org.geolatte.geom.Position; 4 | import org.geolatte.geom.Positions; 5 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 2019-03-27. 9 | */ 10 | public interface TransformOperation

{ 11 | 12 | CoordinateReferenceSystem

getSource(); 13 | CoordinateReferenceSystem getTarget(); 14 | 15 | CoordinateOperation getOperation(); 16 | 17 | default Q forward(P pos) { 18 | double[] out = new double[getTarget().getCoordinateDimension()]; 19 | getOperation().forward(pos.toArray(null), out); 20 | return Positions.mkPosition(getTarget().getPositionClass(), out); 21 | } 22 | 23 | default P reverse(Q pos) { 24 | double[] out = new double[getSource().getCoordinateDimension()]; 25 | getOperation().reverse(pos.toArray(null), out); 26 | return Positions.mkPosition(getSource().getPositionClass(), out); 27 | } 28 | 29 | 30 | TransformOperation reversed(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/trans/UnsupportedTransformException.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs.trans; 2 | 3 | import org.geolatte.geom.crs.CrsId; 4 | 5 | /** 6 | * Created by Karel Maesen, Geovise BVBA on 2019-03-24. 7 | */ 8 | public class UnsupportedTransformException extends RuntimeException { 9 | 10 | public UnsupportedTransformException(CrsId source, CrsId target) { 11 | super(String.format("Can't find transform from %s to %s", source, target)); 12 | } 13 | 14 | public UnsupportedTransformException(CrsId method) { 15 | super(String.format("Can't find operation method with id %s", method)); 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/crs/trans/WithEpsgGOperationMethod.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs.trans; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 02/04/2018. 5 | */ 6 | public interface WithEpsgGOperationMethod { 7 | 8 | /** 9 | * Returns the EPSG code for the operation method 10 | * @return The EPSG Code for the operation method 11 | */ 12 | int getMethodId(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/curve/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Space-filling curves. 3 | * 4 | * Created by maesenka on 07/10/14. 5 | */ 6 | package org.geolatte.geom.curve; -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/AbstractGeometryGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import org.geolatte.geom.Box; 4 | import org.geolatte.geom.Geometry; 5 | import org.geolatte.geom.Position; 6 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 7 | 8 | import java.util.Random; 9 | 10 | /** 11 | * Created by Karel Maesen, Geovise BVBA on 28/09/2018. 12 | */ 13 | abstract class AbstractGeometryGenerator

> implements Generator { 14 | protected final Box

bbox; 15 | protected final Random rnd; 16 | 17 | public AbstractGeometryGenerator(Box

bbox, Random rnd) { 18 | this.bbox = bbox; 19 | this.rnd = rnd; 20 | } 21 | 22 | @Override 23 | abstract public G generate(); 24 | 25 | protected CoordinateReferenceSystem

crs() { 26 | return this.bbox.getCoordinateReferenceSystem(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/Choice.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import java.util.List; 4 | import java.util.Random; 5 | 6 | /** 7 | * Created by Karel Maesen, Geovise BVBA on 2019-08-16. 8 | */ 9 | public class Choice implements Generator { 10 | 11 | private final List choices; 12 | private final Random rnd; 13 | 14 | public static Choice of(List choices) { 15 | return new Choice(choices); 16 | } 17 | 18 | public Choice(List choices, Random rnd) { 19 | this.choices = choices; 20 | this.rnd = rnd; 21 | } 22 | 23 | public Choice(List choices) { 24 | this(choices, new Random()); 25 | } 26 | 27 | @Override 28 | public T generate() { 29 | int index = rnd.nextInt(choices.size()); 30 | return choices.get(index); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/CombinedGeometryGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.Position; 5 | 6 | import java.util.List; 7 | import java.util.Random; 8 | 9 | /** 10 | * Created by Karel Maesen, Geovise BVBA on 28/09/2018. 11 | */ 12 | class CombinedGeometryGenerator

implements Generator> { 13 | 14 | private final Random chooser; 15 | private final List>> generators; 16 | 17 | CombinedGeometryGenerator(Random rnd, List>> generators) { 18 | this.chooser = rnd; 19 | this.generators = generators; 20 | } 21 | 22 | @Override 23 | public Geometry

generate() { 24 | int idx = chooser.nextInt(generators.size()); 25 | return generators.get(idx).generate(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/DefaultGeometryCollectionGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import org.geolatte.geom.*; 4 | import org.geolatte.geom.builder.DSL; 5 | 6 | import java.util.Random; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 28/09/2018. 10 | */ 11 | class DefaultGeometryCollectionGenerator

implements Generator> { 12 | 13 | 14 | private final int numGeoms; 15 | private final Generator> baseGenerator; 16 | 17 | DefaultGeometryCollectionGenerator(int numGeoms, Generator> baseGenerator, Random rnd) { 18 | this.numGeoms = numGeoms; 19 | this.baseGenerator = baseGenerator; 20 | }; 21 | 22 | @Override 23 | @SuppressWarnings("unchecked") 24 | public GeometryCollection

generate() { 25 | Geometry

[] geoms = (Geometry

[]) new Geometry[numGeoms-1]; 26 | baseGenerator.generateArray(geoms); 27 | return DSL.geometrycollection(baseGenerator.generate(), geoms); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/DefaultLineStringGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import org.geolatte.geom.Box; 4 | import org.geolatte.geom.LineString; 5 | import org.geolatte.geom.Position; 6 | import org.geolatte.geom.builder.DSL; 7 | 8 | import java.util.Random; 9 | 10 | /** 11 | * Created by Karel Maesen, Geovise BVBA on 28/09/2018. 12 | */ 13 | class DefaultLineStringGenerator

extends AbstractGeometryGenerator> { 14 | 15 | final private int size; 16 | final private boolean closed; 17 | 18 | DefaultLineStringGenerator(int size, Box

bbox, Random rnd) { 19 | super(bbox, rnd); 20 | this.size = size; 21 | this.closed = false; 22 | } 23 | 24 | @Override 25 | public LineString

generate() { 26 | P[] ps = PositionGenerator.nPositionsWithin(size, bbox, rnd); 27 | if (closed) { 28 | ps[ps.length - 1] = ps[0]; 29 | } 30 | return DSL.linestring(crs(), ps); 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/DefaultMultiLineStringGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import org.geolatte.geom.*; 4 | import org.geolatte.geom.builder.DSL; 5 | 6 | import java.util.Random; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 28/09/2018. 10 | */ 11 | class DefaultMultiLineStringGenerator

extends AbstractGeometryGenerator> { 12 | 13 | private final int numLineString; 14 | private final DefaultLineStringGenerator

lineStrGen; 15 | 16 | DefaultMultiLineStringGenerator(int numLineString, int numPoints, Box

bbox, Random rnd) { 17 | super(bbox, rnd); 18 | this.numLineString = numLineString; 19 | this.lineStrGen = new DefaultLineStringGenerator<>(numPoints, bbox, rnd); 20 | } 21 | 22 | @Override 23 | public MultiLineString

generate() { 24 | LineString

[] linestrings = (LineString

[]) new LineString[numLineString - 1]; 25 | lineStrGen.generateArray(linestrings); 26 | return DSL.multilinestring(lineStrGen.generate(), linestrings); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/DefaultMultiPointGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import org.geolatte.geom.Box; 4 | import org.geolatte.geom.MultiPoint; 5 | import org.geolatte.geom.Point; 6 | import org.geolatte.geom.Position; 7 | import org.geolatte.geom.builder.DSL; 8 | 9 | import java.util.Random; 10 | 11 | /** 12 | * Created by Karel Maesen, Geovise BVBA on 28/09/2018. 13 | */ 14 | class DefaultMultiPointGenerator

extends AbstractGeometryGenerator> { 15 | 16 | 17 | final private Generator> pntGen; 18 | final private int numPnts; 19 | DefaultMultiPointGenerator(int numPnts, Box

bbox, Random rnd) { 20 | super(bbox, rnd); 21 | this.numPnts = numPnts; 22 | pntGen = new DefaultPointGenerator<>(bbox, rnd); 23 | } 24 | 25 | @Override 26 | public MultiPoint

generate() { 27 | Point

[] points = (Point

[]) new Point[numPnts - 1]; 28 | pntGen.generateArray(points); 29 | return DSL.multipoint(pntGen.generate(), points); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/DefaultMultiPolygonGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import org.geolatte.geom.*; 4 | import org.geolatte.geom.builder.DSL; 5 | 6 | import java.util.Random; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 28/09/2018. 10 | */ 11 | class DefaultMultiPolygonGenerator

extends AbstractGeometryGenerator>{ 12 | 13 | 14 | private final int numPolys; 15 | private final DefaultPolygonGenerator

polyGen; 16 | 17 | DefaultMultiPolygonGenerator(int numPolys, int numPoints, Box

bbox, Random rnd) { 18 | super(bbox, rnd); 19 | this.numPolys = numPolys; 20 | this.polyGen = new DefaultPolygonGenerator<>(numPoints, bbox, rnd); 21 | } 22 | 23 | @Override 24 | public MultiPolygon

generate() { 25 | Polygon

[] polys = (Polygon

[]) new Polygon[numPolys - 1]; 26 | polyGen.generateArray(polys); 27 | return DSL.multipolygon(polyGen.generate(), polys); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/DefaultPointGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import org.geolatte.geom.Box; 4 | import org.geolatte.geom.Point; 5 | import org.geolatte.geom.Position; 6 | import org.geolatte.geom.builder.DSL; 7 | 8 | import java.util.Random; 9 | 10 | 11 | import static org.geolatte.geom.generator.PositionGenerator.positionWithin; 12 | 13 | /** 14 | * Created by Karel Maesen, Geovise BVBA on 03/08/2018. 15 | */ 16 | class DefaultPointGenerator

extends AbstractGeometryGenerator> { 17 | 18 | DefaultPointGenerator(Box

bbox, Random rnd) { 19 | super(bbox, rnd); 20 | } 21 | 22 | @Override 23 | public Point

generate() { 24 | return DSL.point(crs(), positionWithin(bbox, rnd) ); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/DefaultPolygonGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import org.geolatte.geom.Box; 4 | import org.geolatte.geom.LinearRing; 5 | import org.geolatte.geom.Polygon; 6 | import org.geolatte.geom.Position; 7 | import org.geolatte.geom.builder.DSL; 8 | 9 | import java.util.Random; 10 | 11 | 12 | import static org.geolatte.geom.builder.DSL.ring; 13 | import static org.geolatte.geom.generator.PositionGenerator.nPositionsWithinAndClosed; 14 | 15 | /** 16 | * Created by Karel Maesen, Geovise BVBA on 28/09/2018. 17 | */ 18 | class DefaultPolygonGenerator

extends AbstractGeometryGenerator> { 19 | 20 | final private int numPoints; 21 | 22 | DefaultPolygonGenerator(int numPoints, Box

bbox, Random rnd) { 23 | super(bbox, rnd); 24 | this.numPoints = numPoints; 25 | } 26 | 27 | @Override 28 | public Polygon

generate() { 29 | P[] ps = nPositionsWithinAndClosed(numPoints, bbox, rnd); 30 | LinearRing

hull = ring(crs(), ps); 31 | return DSL.polygon(hull); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/Generator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 2019-08-16. 5 | */ 6 | public interface Generator { 7 | 8 | T generate(); 9 | 10 | @SuppressWarnings("unchecked") 11 | default void generateArray(T[] ts) { 12 | for(int i = 0; i < ts.length; i++){ 13 | ts[i] = generate(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/generator/PropertyMapGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.generator; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.stream.IntStream; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 2019-08-16. 9 | */ 10 | public class PropertyMapGenerator implements Generator> { 11 | 12 | private final int size; 13 | private final Choice> valueGenerator; 14 | private final Generator keyGenerator; 15 | 16 | public PropertyMapGenerator(int size, Generator keyGenerator, Choice> valueGeneratorChoice) { 17 | this.size = size; 18 | this.keyGenerator = keyGenerator; 19 | valueGenerator = valueGeneratorChoice; 20 | } 21 | 22 | @Override 23 | public Map generate() { 24 | Map map = new HashMap<>(); 25 | IntStream.range(0, size).forEach(i -> { 26 | map.put(keyGenerator.generate(), valueGenerator.generate().generate()); 27 | }); 28 | return map; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/jts/JTSConversionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2011 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.jts; 23 | 24 | /** 25 | * @author Karel Maesen, Geovise BVBA, 2011 26 | */ 27 | public class JTSConversionException extends RuntimeException { 28 | 29 | public JTSConversionException(){ 30 | super(); 31 | } 32 | 33 | public JTSConversionException(String msg){ 34 | super(msg); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /geom/src/main/java/org/geolatte/geom/jts/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * JTS interoperability classes. 3 | * 4 | * Created by maesenka on 07/10/14. 5 | */ 6 | package org.geolatte.geom.jts; -------------------------------------------------------------------------------- /geom/src/test/java/TestSettings.java: -------------------------------------------------------------------------------- 1 | import org.geolatte.geom.codec.db.oracle.Settings; 2 | import org.junit.Test; 3 | 4 | import static org.junit.Assert.assertFalse; 5 | import static org.junit.Assert.assertTrue; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 04/12/16. 9 | */ 10 | public class TestSettings { 11 | 12 | 13 | @Test 14 | public void testFeaturesSdoPointSettoTrue(){ 15 | System.setProperty(Settings.USE_SDO_POINT, "true"); 16 | assertTrue(Settings.useSdoPointType()); 17 | System.setProperty(Settings.USE_SDO_POINT, "1"); 18 | assertTrue(Settings.useSdoPointType()); 19 | //reset to default 20 | System.setProperty(Settings.USE_SDO_POINT, "false"); 21 | } 22 | 23 | @Test 24 | public void testFeaturesSdoPointSettoFalse(){ 25 | System.setProperty(Settings.USE_SDO_POINT, "false"); 26 | assertFalse(Settings.useSdoPointType()); 27 | System.setProperty(Settings.USE_SDO_POINT, "0"); 28 | assertFalse(Settings.useSdoPointType()); 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/AssertHelpers.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | import org.geolatte.geom.codec.Wkt; 4 | 5 | import static org.junit.Assert.assertTrue; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 2019-03-28. 9 | */ 10 | public class AssertHelpers { 11 | 12 | private static final double DEFAULT_PRECISION = 0.05d; 13 | 14 | public static

void assertEquals(Geometry

g1, Geometry

g2) { 15 | GeometryEquality eq = new ApproximateGeometryEquality(DEFAULT_PRECISION); 16 | assertTrue(String.format("\nExpected:\t %s\nReceived:\t %s", 17 | g1 == null ? "" : Wkt.toWkt(g1), 18 | g2 == null ? "" : Wkt.toWkt(g2)), eq.equals(g1, g2)); 19 | } 20 | 21 | public static

void assertEquals(Geometry

g1, Geometry

g2, double delta) { 22 | GeometryEquality eq = new ApproximateGeometryEquality(delta); 23 | assertTrue(String.format("\nExpected:\t %s\nReceived:\t %s", 24 | g1 == null ? "" : Wkt.toWkt(g1), 25 | g2 == null ? "" : Wkt.toWkt(g2)), eq.equals(g1, g2)); 26 | } 27 | 28 | public static

void assertEquals(Envelope

g1, Envelope

g2, double delta) { 29 | WithinTolerancePositionEquality eq = new WithinTolerancePositionEquality(delta); 30 | assertTrue(String.format("\nExpected:\t %s\nReceived:\t %s", 31 | g1 == null ? "" : g1, 32 | g2 == null ? "" : g2), 33 | g1 != null 34 | && g2 != null 35 | && eq.equals(g1.lowerLeft(), g2.lowerLeft()) 36 | && eq.equals(g1.upperRight(), g2.upperRight())); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/CrsMock.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | import org.geolatte.geom.crs.*; 4 | 5 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.addLinearSystem; 6 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.addVerticalSystem; 7 | 8 | /** 9 | * Created by Karel Maesen, Geovise BVBA on 30/11/14. 10 | */ 11 | public class CrsMock { 12 | 13 | public static Geographic2DCoordinateReferenceSystem WGS84 = CrsRegistry.getGeographicCoordinateReferenceSystemForEPSG(4326); 14 | public static CoordinateReferenceSystem WGS84_Z = addVerticalSystem(WGS84, G3D.class, Unit.METER); 15 | public static CoordinateReferenceSystem WGS84_M = addLinearSystem(WGS84, G2DM.class, Unit.METER); 16 | public static CoordinateReferenceSystem WGS84_ZM =addLinearSystem(WGS84_Z, G3DM.class, Unit.METER); 17 | 18 | public static CoordinateReferenceSystem MERCATOR= CoordinateReferenceSystems.WEB_MERCATOR; 19 | public static CoordinateReferenceSystem MERCATOR_Z = addVerticalSystem(MERCATOR, C3D.class, Unit.METER); 20 | public static CoordinateReferenceSystem MERCATOR_M = addLinearSystem(MERCATOR, C2DM.class, Unit.METER); 21 | public static CoordinateReferenceSystem MERCATOR_ZM =addLinearSystem(MERCATOR_Z, C3DM.class, Unit.METER); 22 | 23 | public static CoordinateReferenceSystem crs = CoordinateReferenceSystems.PROJECTED_2D_METER; 24 | public static CoordinateReferenceSystem crsZ = addVerticalSystem(crs, C3D.class, Unit.METER); 25 | 26 | public static CoordinateReferenceSystem crsM = addLinearSystem(crs, C2DM.class, Unit.METER); 27 | public static CoordinateReferenceSystem crsZM = addLinearSystem(crsZ, C3DM.class, Unit.METER); 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/DecimalDegreeTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.geolatte.geom.DecimalDegree.parseDMSLat; 6 | import static org.geolatte.geom.DecimalDegree.parseDMSLon; 7 | import static org.junit.Assert.assertEquals; 8 | import static org.junit.Assert.assertTrue; 9 | 10 | /** 11 | * Created by Karel Maesen, Geovise BVBA on 21/07/17. 12 | */ 13 | public class DecimalDegreeTest { 14 | 15 | @Test 16 | public void testDMS(){ 17 | assertEquals("4° 20' 30.00''E 50° 10' 20.00''N", DecimalDegree.DMS(4.341667, 50.172222)); 18 | } 19 | 20 | @Test 21 | public void testSecondsToRadians(){ 22 | assertEquals(0.0000026858677933494, DecimalDegree.secondsToRadians(0.554), Math.ulp(0.554)); 23 | } 24 | 25 | @Test 26 | public void testparseDMS(){ 27 | WithinTolerancePositionEquality eq = new WithinTolerancePositionEquality(0.00005); 28 | assertTrue( 29 | eq.equals(new G2D(4.341667, 50.172222), 30 | DecimalDegree.parseDMS("4 20' 30.00''E 50 10' 20.00''N") 31 | ) 32 | ); 33 | } 34 | 35 | @Test 36 | public void testParseDMSLat() { 37 | assertEquals( 50.172222, parseDMSLat("50 10' 20.00''N"), 0.00001); 38 | assertEquals(52.1561606, parseDMSLat("52°09'22.178''N"), 0.00001); 39 | } 40 | 41 | 42 | @Test 43 | public void testParseDMSLon() { 44 | assertEquals( 4.341667, parseDMSLon("4 20' 30.00''E"), 0.00001); 45 | 46 | } 47 | 48 | 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/ForceToCrsTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | import static org.geolatte.geom.builder.DSL.*; 4 | import org.junit.Test; 5 | 6 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.PROJECTED_2D_METER; 7 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.PROJECTED_3DM_METER; 8 | import static org.junit.Assert.assertEquals; 9 | 10 | public class ForceToCrsTest { 11 | 12 | 13 | @Test 14 | public void test2DForceTo3DM(){ 15 | Geometry geom = point(PROJECTED_2D_METER, c(1, 2)); 16 | Geometry forced = geom.toCrs(PROJECTED_3DM_METER, 0.0); 17 | assertEquals(point(PROJECTED_3DM_METER, c(1, 2, 0, 0)), forced); 18 | } 19 | 20 | @Test 21 | public void test3DMForceTo2D(){ 22 | Geometry geom = point(PROJECTED_3DM_METER, c(1, 2, 0, 0)); 23 | Geometry forced = geom.toCrs(PROJECTED_2D_METER, 0.0); 24 | assertEquals(point(PROJECTED_2D_METER, c(1, 2)), forced); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/NestedPositionSequenceTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 06/02/16. 9 | */ 10 | public class NestedPositionSequenceTest { 11 | 12 | @Test 13 | public void testReverse() { 14 | PositionSequenceBuilder builder = PositionSequenceBuilders.fixedSized(2, C2D.class); 15 | PositionSequence p = builder.add(1, 0).add(2, 3).toPositionSequence(); 16 | PositionSequenceBuilder builder2 = PositionSequenceBuilders.fixedSized(3, C2D.class); 17 | PositionSequence p2 = builder2.add(5,6).add(7,8).add(10,11).toPositionSequence(); 18 | 19 | NestedPositionSequence nps = new NestedPositionSequence(new PositionSequence[]{p, p2}); 20 | 21 | PositionSequenceBuilder builder3 = PositionSequenceBuilders.fixedSized(2, C2D.class); 22 | PositionSequence rp = builder3.add(2, 3).add(1, 0).toPositionSequence(); 23 | PositionSequenceBuilder builder4 = PositionSequenceBuilders.fixedSized(3, C2D.class); 24 | PositionSequence rp2 = builder4.add(10,11).add(7,8).add(5,6).toPositionSequence(); 25 | 26 | NestedPositionSequence rnps = new NestedPositionSequence(new PositionSequence[]{rp2, rp}); 27 | 28 | assertEquals(rnps, nps.reverse()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/PositionTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom; 2 | 3 | import org.geolatte.geom.crs.*; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.*; 7 | 8 | /** 9 | * Created by maesenka on 12/08/14. 10 | */ 11 | public class PositionTest { 12 | 13 | @Test 14 | public void testGetCoordinateDimension() { 15 | CoordinateReferenceSystem crs = new Geographic2DCoordinateReferenceSystem(CrsId.valueOf("EPSG", 1), 16 | "test", 17 | new EllipsoidalCoordinateSystem2D(CoordinateSystemAxis.mkLatAxis(), CoordinateSystemAxis.mkLonAxis())); 18 | 19 | G2D pos = new G2D(5, 50); 20 | double testLon = pos.getCoordinate(CoordinateSystemAxis.mkLonAxis()); 21 | double testLat = pos.getCoordinate(CoordinateSystemAxis.mkLatAxis()); 22 | assertEquals(5, testLon, 0.00001); 23 | assertEquals(50, testLat, 0.0001); 24 | 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/TestByteBufferInvalidCharacters.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import static org.junit.Assert.fail; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.List; 8 | import org.geolatte.geom.ByteBuffer; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.junit.runners.Parameterized; 12 | import org.junit.runners.Parameterized.Parameters; 13 | 14 | @RunWith(Parameterized.class) 15 | public class TestByteBufferInvalidCharacters { 16 | 17 | @Parameters 18 | public static Collection charactersToTest() { 19 | List characters = new ArrayList<>(); 20 | for (char i = 0; i < 256; ++i) { 21 | if ((i >= 'A' && i <= 'F') 22 | || (i >= 'a' && i <= 'f') 23 | || (i >= '0' && i <= '9') 24 | || i == '+' || i == '-' 25 | ) { 26 | continue; 27 | } 28 | characters.add(new Object[]{i}); 29 | } 30 | return characters; 31 | } 32 | 33 | private final char characterToTest; 34 | 35 | public TestByteBufferInvalidCharacters(char characterToTest) { 36 | this.characterToTest = characterToTest; 37 | } 38 | 39 | @Test(expected = NumberFormatException.class) 40 | public void testThatNumberFormatExceptionIsThrown() { 41 | StringBuilder sb = new StringBuilder(); 42 | sb.append(characterToTest); 43 | sb.append("0"); 44 | ByteBuffer.from(sb.toString()); 45 | fail("string " + sb.toString() + " should trigger a number format exception. characterToTest=" 46 | + (int) characterToTest); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/TestMySqlWkbCodec.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | 4 | import org.geolatte.geom.*; 5 | import org.geolatte.geom.builder.DSL; 6 | import org.junit.Test; 7 | 8 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 9 | import static org.junit.Assert.assertSame; 10 | import static org.junit.Assert.assertTrue; 11 | 12 | public class TestMySqlWkbCodec { 13 | 14 | 15 | final private WkbDecoder decoder = new MySqlWkbDecoder(); 16 | final private WkbEncoder encoder = new MySqlWkbEncoder(); 17 | 18 | /** 19 | * This encodes an empty geometry into a geomtrycollection(). 20 | * 21 | * The documentation states: "The only valid empty geometry is represented in the form 22 | * of an empty geometry collection value. MySQL does not support 23 | * GIS EMPTY values such as POINT EMPTY. 24 | */ 25 | @Test 26 | public void testEmptyGeometryEncoding(){ 27 | Geometry geometry = DSL.linestring(WGS84); 28 | ByteBuffer wkb = encoder.encode(geometry); 29 | Geometry decoded = decoder.decode(wkb, WGS84); 30 | assertTrue(decoded.isEmpty()); 31 | assertSame(decoded.getGeometryType(), GeometryType.GEOMETRYCOLLECTION); 32 | 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/TestPostgisJDBCWithSRIDUnitTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the GeoLatte project. 3 | * 4 | * GeoLatte is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * GeoLatte is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with GeoLatte. If not, see . 16 | * 17 | * Copyright (C) 2010 - 2012 and Ownership of code is shared by: 18 | * Qmino bvba - Romeinsestraat 18 - 3001 Heverlee (http://www.qmino.com) 19 | * Geovise bvba - Generaal Eisenhowerlei 9 - 2140 Antwerpen (http://www.geovise.com) 20 | */ 21 | 22 | package org.geolatte.geom.codec; 23 | 24 | import org.geolatte.geom.codec.testcases.PostgisJDBCWithSRIDTestInputs; 25 | import org.geolatte.geom.codec.testcases.WktWkbCodecTestBase; 26 | 27 | /** 28 | * @author Karel Maesen, Geovise BVBA 29 | * creation-date: 11/1/12 30 | */ 31 | public class TestPostgisJDBCWithSRIDUnitTests extends TestPostgisJDBCUnitTests { 32 | 33 | PostgisJDBCWithSRIDTestInputs testCasesWithSRID = new PostgisJDBCWithSRIDTestInputs(); 34 | 35 | @Override 36 | protected WktWkbCodecTestBase getTestCases() { 37 | return testCasesWithSRID; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/TestPostgisWkbV2EncoderDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.ByteBuffer; 4 | import org.geolatte.geom.G2D; 5 | import org.geolatte.geom.Geometry; 6 | import org.geolatte.geom.Point; 7 | import org.geolatte.geom.crs.CoordinateReferenceSystems; 8 | import org.geolatte.geom.crs.Unit; 9 | import org.geolatte.geom.codec.testcases.PostgisTestCases; 10 | import org.junit.Test; 11 | 12 | import static org.junit.Assert.assertTrue; 13 | 14 | public class TestPostgisWkbV2EncoderDecoder extends TestPostgisWkbEncoderDecoder{ 15 | 16 | @Test 17 | public void test_empty_point() { 18 | Geometry g = new Point(CoordinateReferenceSystems.mkGeographic(Unit.DEGREE)); 19 | ByteBuffer buf = Wkb.newEncoder(Wkb.Dialect.POSTGIS_EWKB_2).encode(g); 20 | ByteBuffer byteBuffer = testcases.getWKB(PostgisTestCases.EMPTY_POINT_USING_NAN); 21 | Geometry geom = decode(byteBuffer); 22 | assertTrue(geom.isEmpty()); 23 | testEncoding(byteBuffer, geom); 24 | } 25 | 26 | @Override 27 | protected WkbEncoder encoder() { 28 | return new PostgisWkbV2Encoder(); 29 | } 30 | 31 | @Override 32 | protected WkbDecoder decoder() { 33 | return new PostgisWkbDecoder(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/TestWkbDecodingIdempotent.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.*; 4 | import org.geolatte.geom.builder.DSL; 5 | import org.geolatte.geom.crs.CrsRegistry; 6 | import org.geolatte.geom.crs.ProjectedCoordinateReferenceSystem; 7 | import org.junit.Test; 8 | 9 | import static org.geolatte.geom.builder.DSL.point; 10 | import static org.junit.Assert.assertEquals; 11 | 12 | /** 13 | * 14 | */ 15 | public class TestWkbDecodingIdempotent { 16 | 17 | ProjectedCoordinateReferenceSystem crs = CrsRegistry.getProjectedCoordinateReferenceSystemForEPSG(31370); 18 | 19 | @Test 20 | public void testWkbConversionShouldBeStable() { 21 | Geometry original = point(crs, DSL.c(68878.8400879, 169038.177124)); 22 | 23 | String originalWkb = "01010000208A7A000084020071EDD0F040DBFCBF6A71A20441"; 24 | 25 | assertEquals(originalWkb, Wkb.toWkb(original).toString()); 26 | 27 | // geom to wkb to geom blijft stabliel 28 | assertEquals(Wkb.fromWkb(Wkb.toWkb(original)),original); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/TestWktDecodingBugs.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * Created by Karel Maesen, Geovise BVBA on 13/03/15. 7 | */ 8 | public class TestWktDecodingBugs { 9 | 10 | 11 | @Test(expected=WktDecodeException.class) 12 | public void test_issue_31(){ 13 | Wkt.newDecoder(Wkt.Dialect.POSTGIS_EWKT_1).decode("POLYGON( 24.881973486328125 60.15671327918588, 24.936218481445312 60.160642536827424, 24.978103857421875 60.16696253094966, 24.881973486328125 60.15671327918588 )"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/TestWktDecodingIdempotent.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.geolatte.geom.crs.CrsRegistry; 5 | import org.geolatte.geom.crs.ProjectedCoordinateReferenceSystem; 6 | import org.junit.Test; 7 | 8 | import static org.geolatte.geom.builder.DSL.c; 9 | import static org.geolatte.geom.builder.DSL.point; 10 | import static org.junit.Assert.assertEquals; 11 | 12 | /** 13 | * 14 | */ 15 | public class TestWktDecodingIdempotent { 16 | 17 | ProjectedCoordinateReferenceSystem crs = CrsRegistry.getProjectedCoordinateReferenceSystemForEPSG(31370); 18 | 19 | @Test 20 | public void testFastNumberReader() { 21 | SimpleTokenizer tokenizer = new SimpleTokenizer("169038.177124 "); 22 | double v = tokenizer.fastReadNumber(); 23 | assertEquals("169038.177124", String.valueOf(v)); 24 | 25 | } 26 | 27 | @Test 28 | public void testWktConversionShouldBeIdempotent() { 29 | Geometry original = point(crs, c(68878.8400879, 169038.177124)); 30 | 31 | String originalWkt = "SRID=31370;POINT(68878.8400879 169038.177124)"; 32 | assertEquals(originalWkt, Wkt.toWkt(original)); 33 | 34 | // geom to wkb to geom zou stabiel moeten blijven 35 | assertEquals(Wkt.fromWkt(Wkt.toWkt(original)), original); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/db/oracle/SDOElemInfoSpecTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | /** 4 | * Blackbox tests. 5 | * 6 | * This tests the specification of SDOElemInfo 7 | */ 8 | public class SDOElemInfoSpecTest { 9 | 10 | 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/db/oracle/SDOGeometryHelper.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import java.math.BigDecimal; 4 | 5 | /** 6 | * Created by Karel Maesen, Geovise BVBA on 28/03/15. 7 | */ 8 | public class SDOGeometryHelper { 9 | 10 | 11 | public static SDOGeometry sdoGeometry(Integer gtype, int srid, SDOPoint sdoPoint, int[] elemInfo, Double[] ordinates ) { 12 | 13 | ElemInfo info = elemInfo == null ? null : new ElemInfo(toBigDecimalArray(elemInfo)); 14 | Ordinates o = ordinates == null ? null : new Ordinates(ordinates); 15 | 16 | SDOGeometry result = new SDOGeometry( 17 | SDOGType.parse(gtype), 18 | srid, 19 | sdoPoint, 20 | info , 21 | o); 22 | 23 | return result; 24 | } 25 | 26 | public static SDOPoint sdoPoint(double x, double y, double z) { 27 | return new SDOPoint(x, y, z); 28 | } 29 | 30 | public static SDOPoint sdoPoint(double x, double y) { 31 | return new SDOPoint(x, y); 32 | } 33 | 34 | private static BigDecimal[] toBigDecimalArray(int[] ints) { 35 | BigDecimal[] result = new BigDecimal[ints.length]; 36 | for (int i = 0; i < ints.length; i++) { 37 | result[i] = new BigDecimal(ints[i]); 38 | } 39 | return result; 40 | } 41 | 42 | 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/db/oracle/SmallArcBugTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertNotNull; 7 | 8 | // for testing issue #151 9 | public class SmallArcBugTest { 10 | 11 | @Test 12 | public void testCase1(){ 13 | int[] elems = {1,1005,3,1,2,1,15,2,2,19,2,1}; 14 | Double[] coords = {209499.475,578259.358,209503.708,578359.503,209505.325,578409.615,209505.144,578416.324,209504.933,578419.552,209505.118,578420.213,209505.693,578421.019,209500.401,578421.362,209500.401,578421.361,209500.402,578421.361,209500.832,578421.033,209501.057,578420.591,209501.063,578420.225,209499.607,578371.806,209497.623,578305.131,209495.574,578238.184,209495.409,578222.433,209495.062,578211.578,209498.02,578211.469,209499.475,578259.358}; 15 | SDOGeometry sdo = SDOGeometryHelper.sdoGeometry( 16 | 2003, 28992, null, elems, coords 17 | ); 18 | Geometry geom = Decoders.decode(sdo); 19 | assertNotNull(geom); //check that this doesn't throw an exception 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/db/oracle/TestForIssue67.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.G2D; 4 | import org.geolatte.geom.Geometry; 5 | import org.geolatte.geom.jts.JTS; 6 | import org.junit.After; 7 | import org.junit.Before; 8 | import org.junit.Ignore; 9 | import org.junit.Test; 10 | 11 | import java.sql.Connection; 12 | import java.sql.DriverManager; 13 | import java.sql.SQLException; 14 | import java.sql.Struct; 15 | import java.util.Properties; 16 | 17 | import static org.geolatte.geom.builder.DSL.g; 18 | import static org.geolatte.geom.builder.DSL.point; 19 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 20 | import static org.junit.Assert.assertEquals; 21 | 22 | /** 23 | * Created by Karel Maesen, Geovise BVBA on 01/08/2018. 24 | */ 25 | public class TestForIssue67 { 26 | 27 | private Connection conn; 28 | 29 | @Before 30 | public void before() throws SQLException { 31 | System.setProperty("GEOLATTE_USE_SDO_POINT_TYPE", "true"); 32 | } 33 | 34 | @After 35 | public void after() throws SQLException { 36 | System.setProperty("GEOLATTE_USE_SDO_POINT_TYPE", "false"); 37 | } 38 | 39 | @Test 40 | public void testArrayStoreExceptionOn() throws SQLException { 41 | Geometry geom = point(WGS84, g(4.96 , 53.56)); 42 | SDOGeometry sdoGeometry = Encoders.encode(geom); 43 | SDOGeometry expected = new SDOGeometry(SDOGType.parse(2001), 4326, new SDOPoint(4.96, 53.56), null ,null); 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/db/oracle/TestGeometryCollectionSdoDecoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.G2D; 4 | import org.geolatte.geom.Geometry; 5 | import org.geolatte.geom.AbstractGeometryCollection; 6 | import org.geolatte.geom.crs.CrsRegistry; 7 | import org.geolatte.geom.crs.GeographicCoordinateReferenceSystem; 8 | 9 | import static org.geolatte.geom.builder.DSL.*; 10 | import static org.junit.Assert.assertEquals; 11 | 12 | import org.junit.Test; 13 | 14 | /** 15 | * Created by Karel Maesen, Geovise BVBA on 01/04/15. 16 | */ 17 | public class TestGeometryCollectionSdoDecoder { 18 | 19 | GeographicCoordinateReferenceSystem wgs84 = CrsRegistry.getGeographicCoordinateReferenceSystemForEPSG(4326); 20 | 21 | @Test 22 | public void testGeometryCollection(){ 23 | SDOGeometry sdo = SDOGeometryHelper.sdoGeometry(2004, 4326, null, new int[]{ 1, 1, 1, 3, 2, 1, 7, 1003, 1, 17, 2003, 1} , 24 | new Double[]{10.,5.,10.,10.,20.,10.,0.,0.,50.,0.,100.,100.,0.,100.,0.,0.,1.,1.,49.,1.,99.,99.,1.,99.,1.,1.}); 25 | 26 | AbstractGeometryCollection> geom = geometrycollection(wgs84, point(g(10, 5)), linestring(g(10, 10) 27 | , g(20, 10)), polygon( 28 | ring(g(0, 0), g(50, 0), g(100, 100), g(0, 100), g(0, 0)), 29 | ring(g(1, 1), g(49, 1), g(99, 99), g(1, 99), g(1, 1)))); 30 | 31 | assertEquals(geom, Decoders.decode(sdo)); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/db/oracle/TestGeometryCollectionSdoEncoder.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.G2D; 4 | import org.geolatte.geom.Geometry; 5 | import org.geolatte.geom.AbstractGeometryCollection; 6 | import org.geolatte.geom.crs.CrsRegistry; 7 | import org.geolatte.geom.crs.GeographicCoordinateReferenceSystem; 8 | import org.junit.Test; 9 | 10 | import static org.geolatte.geom.builder.DSL.*; 11 | import static org.geolatte.geom.builder.DSL.g; 12 | import static org.junit.Assert.assertEquals; 13 | 14 | /** 15 | * Created by Karel Maesen, Geovise BVBA on 01/04/15. 16 | */ 17 | public class TestGeometryCollectionSdoEncoder { 18 | 19 | GeographicCoordinateReferenceSystem wgs84 = CrsRegistry.getGeographicCoordinateReferenceSystemForEPSG(4326); 20 | 21 | 22 | @Test 23 | public void testGeometryCollection(){ 24 | SDOGeometry expected = SDOGeometryHelper.sdoGeometry(2004, 4326, null, new int[]{ 1, 1, 1, 3, 2, 1, 7, 1003, 1} , 25 | new Double[]{10. ,5. , 10. ,10. , 20. ,10. , 10. ,105. , 15. ,105. , 20. ,110. , 10. ,110., 26 | 10., 105.}); 27 | 28 | AbstractGeometryCollection> geom = geometrycollection(wgs84, point(g(10, 5)), linestring(g(10, 10) 29 | , g(20, 10)), polygon(ring(g(10, 105), g(15, 105), g(20, 110), g(10, 110), g(10, 105)))); 30 | 31 | assertEquals(expected, Encoders.encode(geom)); 32 | 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/db/oracle/TestMultiLineSdoCodec.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import junit.framework.TestCase; 4 | import org.geolatte.geom.G2D; 5 | import org.geolatte.geom.Geometry; 6 | import org.geolatte.geom.MultiLineString; 7 | 8 | import static org.geolatte.geom.CrsMock.WGS84; 9 | import static org.geolatte.geom.builder.DSL.*; 10 | import org.junit.Test; 11 | 12 | public class TestMultiLineSdoCodec extends TestCase { 13 | 14 | @Test 15 | public void testBasic(){ 16 | MultiLineString mls = multilinestring(WGS84, 17 | linestring(g(1,2), g(3,4)), 18 | linestring(g(4,6),g(2, 1))); 19 | SDOGeometry encoded = Encoders.encode(mls); 20 | Geometry decoded = Decoders.decode(encoded); 21 | assertEquals(mls, decoded); 22 | } 23 | 24 | @Test 25 | public void testEmpty(){ 26 | MultiLineString mls = multilinestring(WGS84); 27 | SDOGeometry encoded = Encoders.encode(mls); 28 | Geometry decoded = Decoders.decode(encoded); 29 | assertEquals(mls, decoded); 30 | } 31 | 32 | 33 | } -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/db/oracle/TestMultiPolygonSdoCodec.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.G2D; 4 | import org.geolatte.geom.MultiPolygon; 5 | import org.junit.Test; 6 | 7 | import static org.geolatte.geom.CrsMock.WGS84; 8 | import static org.geolatte.geom.builder.DSL.*; 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class TestMultiPolygonSdoCodec { 12 | 13 | @Test 14 | public void testBasic() { 15 | MultiPolygon mpoly = multipolygon(WGS84, 16 | polygon( 17 | ring(g(-10, -10), g(10, -10), g(10, 10), g(-10, 10), g(-10, -10)), 18 | ring(g(0, 0), g(0, 1), g(1, 1), g(1, 0), g(0, 0)) 19 | ), 20 | polygon( 21 | ring(g(-10, -10), g(10, -10), g(10, 10), g(-10, 10), g(-10, -10)) 22 | ) 23 | ); 24 | SDOGeometry sdo = Encoders.encode(mpoly); 25 | assertEquals(mpoly, Decoders.decode(sdo)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/db/oracle/TestSdoEncodeBug78.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.db.oracle; 2 | 3 | import org.geolatte.geom.G2D; 4 | import org.geolatte.geom.Geometry; 5 | import org.geolatte.geom.codec.Wkt; 6 | import org.geolatte.geom.crs.CoordinateReferenceSystems; 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.assertNotNull; 10 | 11 | /** 12 | * Created by Karel Maesen, Geovise BVBA on 2019-03-20. 13 | */ 14 | public class TestSdoEncodeBug78 { 15 | 16 | @Test 17 | public void testPolygonWithVerySmallPolygon() { 18 | 19 | Geometry poly = Wkt.fromWkt(WKT, CoordinateReferenceSystems.WGS84); 20 | 21 | PolygonSdoEncoder encoder = new PolygonSdoEncoder(); 22 | 23 | assertNotNull(encoder.encode(poly)); 24 | 25 | } 26 | 27 | static String WKT = "POLYGON((-88.101304825 30.791176733, -88.101303916 30.791176749, -88.101304 30.791177, -88.101304825 30.791176733))"; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/codec/testcases/BoundingBoxTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.codec.testcases; 2 | 3 | import org.geolatte.geom.Box; 4 | import org.geolatte.geom.C2D; 5 | import org.geolatte.geom.MultiPoint; 6 | import org.junit.Test; 7 | 8 | import static org.geolatte.geom.builder.DSL.*; 9 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WEB_MERCATOR; 10 | import static org.junit.Assert.assertEquals; 11 | import static org.junit.Assert.assertTrue; 12 | 13 | public class BoundingBoxTest { 14 | 15 | @Test 16 | public void checkBoundingBoxIsConstructedCorrectly(){ 17 | C2D p1 = c(-2, -2); 18 | C2D p2 = c(-1, -1); 19 | MultiPoint mp = multipoint(point(WEB_MERCATOR, p1), point(WEB_MERCATOR, p2)); 20 | Box bb = mp.getBoundingBox(); 21 | assertEquals(bb.lowerLeft(), p1); 22 | assertEquals(bb.upperRight(), p2); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/crs/trans/GeographicToGeocentricConversionTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs.trans; 2 | 3 | import org.geolatte.geom.crs.CoordinateReferenceSystems; 4 | import org.geolatte.geom.crs.Geographic2DCoordinateReferenceSystem; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | 9 | /** 10 | * Created by Karel Maesen, Geovise BVBA on 21/07/17. 11 | */ 12 | public class GeographicToGeocentricConversionTest { 13 | 14 | Geographic2DCoordinateReferenceSystem wgs84 = CoordinateReferenceSystems.WGS84; 15 | GeographicToGeocentricConversion toGeocentric = new GeographicToGeocentricConversion( wgs84); 16 | 17 | 18 | @Test 19 | public void testForward(){ 20 | 21 | double[] result = new double[3]; 22 | toGeocentric.forward(new double[]{2.12955, 53.80939444, 73.0}, result); 23 | assertEquals(3771793.968, result[0], 0.01); 24 | assertEquals(140253.342, result[1], 0.01); 25 | assertEquals(5124304.349, result[2], 0.01); 26 | 27 | } 28 | 29 | @Test 30 | public void testReverse(){ 31 | 32 | double[] result = new double[3]; 33 | toGeocentric.reverse(new double[]{3771793.97, 140253.34,5124304.35 }, result); 34 | assertEquals(2.12955, result[0], 0.001); 35 | assertEquals(53.809394, result[1], 0.001); 36 | assertEquals(73.0, result[2], 0.01); 37 | } 38 | 39 | 40 | } -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/crs/trans/PositionVectorTransformationTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs.trans; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 21/07/17. 9 | */ 10 | public class PositionVectorTransformationTest { 11 | 12 | PositionVectorTransformation wgs72Towgs84 = new PositionVectorTransformation( 0, 0, 4.5, 0, 0, 0.554, 0.219); 13 | 14 | @Test 15 | public void testForward(){ 16 | double[] in = new double[]{3657660.66, 255768.55, 5201382.11}; 17 | double[] out = new double[3]; 18 | wgs72Towgs84.forward(in, out); 19 | assertEquals(3657660.78, out[0], 0.01); 20 | assertEquals( 255778.43, out[1], 0.01); 21 | assertEquals(5201387.75, out[2], 0.01); 22 | } 23 | 24 | 25 | @Test 26 | public void testReverse(){ 27 | double[] in = new double[]{3657660.78, 255778.43, 5201387.75}; 28 | double[] out = new double[3]; 29 | wgs72Towgs84.reverse(in, out); 30 | assertEquals(3657660.66, out[0], 0.01); 31 | assertEquals( 255768.55, out[1], 0.01); 32 | assertEquals(5201382.11, out[2], 0.01); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/crs/trans/TestEnvelopeTransform.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs.trans; 2 | 3 | import org.geolatte.geom.C2D; 4 | import org.geolatte.geom.Envelope; 5 | import org.geolatte.geom.G2D; 6 | import org.junit.Test; 7 | 8 | import static org.geolatte.geom.AssertHelpers.assertEquals; 9 | import static org.geolatte.geom.builder.DSL.c; 10 | import static org.geolatte.geom.builder.DSL.g; 11 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WEB_MERCATOR; 12 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 13 | 14 | /** 15 | * Created by Karel Maesen, Geovise BVBA on 2019-03-28. 16 | */ 17 | public class TestEnvelopeTransform { 18 | 19 | private EnvelopeTransform transform = new EnvelopeTransform<>(TransformOperations.from(WGS84, WEB_MERCATOR)); 20 | 21 | @Test 22 | public void testEnvelopeTransformForward(){ 23 | Envelope env = new Envelope<>(g(5, 50), g(6, 51), WGS84); 24 | Envelope exp = new Envelope<> (c(556597.4539663679, 6446275.841017158),c(667916.9447596414, 6621293.722740163), WEB_MERCATOR); 25 | assertEquals(exp, transform.forward(env), 0.00001); 26 | } 27 | 28 | @Test 29 | public void testEnvelopeTransformReverse(){ 30 | Envelope env = new Envelope<> (c(556597.4539663679, 6446275.841017158),c(667916.9447596414, 6621293.722740163), WEB_MERCATOR); 31 | Envelope exp = new Envelope<>(g(5, 50), g(6, 51), WGS84); 32 | assertEquals(exp, transform.reverse(env), 0.00001); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/crs/trans/projections/PseudoMercatorTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.crs.trans.projections; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 02/04/2018. 9 | */ 10 | public class PseudoMercatorTest { 11 | 12 | @Test 13 | public void testCase1() { 14 | PseudoMercator pseudoMercator = new PseudoMercator(); 15 | double[] in = new double[]{3, 50}; 16 | double[] out = new double[2]; 17 | pseudoMercator.forward(in, out); 18 | assertEquals(333958.47237982, out[0], 0.00001); 19 | assertEquals(6446275.84101716, out[1], 0.00001); 20 | pseudoMercator.reverse(out, in); 21 | assertEquals(3, in[0], 0.00001); 22 | assertEquals(50, in[1], 0.00001); 23 | } 24 | 25 | @Test 26 | public void testCase2() { 27 | PseudoMercator pseudoMercator = new PseudoMercator(); 28 | double[] in = new double[2]; 29 | double[] out = new double[2]; 30 | in[0] = Math.toDegrees(-1.751147016); 31 | in[1] = Math.toDegrees(0.425542460); 32 | pseudoMercator.forward(in, out); 33 | double difference = -11169055.58 - out[0]; 34 | //TODO -- can we improve accuracy?? 35 | assertEquals(-11169055.58, out[0], 0.01); 36 | assertEquals(2800000.0, out[1], 0.01); 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/support/generator/CircleGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.support.generator; 2 | 3 | import org.geolatte.geom.cga.Circle; 4 | 5 | /** 6 | * Created by Karel Maesen, Geovise BVBA on 03/03/15. 7 | */ 8 | public class CircleGenerator implements Generator { 9 | 10 | final Generator cGen; 11 | final Generator rGen; 12 | 13 | public CircleGenerator(double lowestCoordinate, double highestCoordinate, double maxRadius) { 14 | cGen = StdGenerators.between(lowestCoordinate, highestCoordinate); 15 | rGen = StdGenerators.between(0.0000000001, maxRadius); 16 | } 17 | 18 | public Circle sample() { 19 | double x = cGen.sample(); 20 | double y = cGen.sample(); 21 | double radius = rGen.sample(); 22 | return new Circle(x, y, radius); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/support/generator/Generator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.support.generator; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 03/03/15. 5 | */ 6 | public interface Generator

{ 7 | 8 | public P sample(); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/support/generator/PositionGenerator.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.support.generator; 2 | 3 | import org.geolatte.geom.Position; 4 | import org.geolatte.geom.PositionFactory; 5 | import org.geolatte.geom.Positions; 6 | 7 | /** 8 | * Created by Karel Maesen, Geovise BVBA on 03/03/15. 9 | */ 10 | public class PositionGenerator

implements Generator

{ 11 | 12 | final private PositionFactory

factory; 13 | final private double[] coordinates; 14 | final private Generator cGen; 15 | 16 | public PositionGenerator(Class

positionClass, Generator coordinateGenerator) { 17 | this.factory = Positions.getFactoryFor(positionClass); 18 | this.coordinates = new double[factory.getCoordinateDimension()]; 19 | this.cGen = coordinateGenerator; 20 | } 21 | 22 | @Override 23 | public P sample() { 24 | for (int i = 0; i < coordinates.length; i++) { 25 | coordinates[i] = cGen.sample(); 26 | } 27 | return factory.mkPosition(coordinates); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /geom/src/test/java/org/geolatte/geom/support/generator/StdGenerators.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.support.generator; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 03/03/15. 5 | */ 6 | public class StdGenerators { 7 | 8 | public static Generator between(final double min, final double max){ 9 | return new Generator() { 10 | 11 | @Override 12 | public Double sample() { 13 | return min + Math.random() * (max - min); 14 | } 15 | }; 16 | } 17 | 18 | public static Generator bernouilly(final double probabilityOfSuccess){ 19 | return new Generator(){ 20 | 21 | @Override 22 | public Boolean sample() { 23 | if ( probabilityOfSuccess < 0 || probabilityOfSuccess > 1) throw new IllegalArgumentException(); 24 | double r = Math.random(); 25 | return r <= probabilityOfSuccess; 26 | } 27 | }; 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /geom/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, S 2 | 3 | log4j.appender.S = org.apache.log4j.ConsoleAppender 4 | log4j.appender.S.layout = org.apache.log4j.PatternLayout 5 | log4j.appender.S.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n 6 | 7 | -------------------------------------------------------------------------------- /json/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.geolatte 5 | geolatte 6 | ${revision} 7 | 8 | geolatte-geojson 9 | 10 | This geoLatte-geojson library provides a Jackson module for serializing Geometry objects to GeoJson 11 | specification. 12 | 13 | https://github.com/geolatte/geolatte-geom 14 | 15 | 16 | 17 | org.geolatte 18 | geolatte-geom 19 | ${project.version} 20 | 21 | 22 | com.fasterxml.jackson.core 23 | jackson-databind 24 | 2.14.0-rc1 25 | true 26 | 27 | 28 | junit 29 | junit 30 | 4.13.1 31 | test 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /json/src/main/java/org/geolatte/geom/json/BoxSerializer.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.databind.JsonSerializer; 5 | import com.fasterxml.jackson.databind.SerializerProvider; 6 | import org.geolatte.geom.Box; 7 | import org.geolatte.geom.Position; 8 | 9 | import java.io.IOException; 10 | import java.util.Arrays; 11 | 12 | public class BoxSerializer

extends JsonSerializer> { 13 | 14 | @Override 15 | public void serialize(Box

box, JsonGenerator gen, SerializerProvider serializers) throws IOException { 16 | final double[] bbox = concat(box.lowerLeft().toArray(null), box.upperRight().toArray(null)); 17 | gen.writeArray(bbox, 0, bbox.length); 18 | } 19 | 20 | @Override 21 | public boolean isEmpty(SerializerProvider provider, Box

box) { 22 | return box == null || box.isEmpty(); 23 | } 24 | 25 | private double[] concat(double[] pos1, double[] pos2) { 26 | double[] result = Arrays.copyOf(pos1, pos1.length + pos2.length); 27 | System.arraycopy(pos2, 0, result, pos1.length, pos2.length); 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /json/src/main/java/org/geolatte/geom/json/FeatureCollectionDeserializer.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.core.ObjectCodec; 5 | import com.fasterxml.jackson.databind.DeserializationContext; 6 | import com.fasterxml.jackson.databind.JsonDeserializer; 7 | import com.fasterxml.jackson.databind.JsonNode; 8 | import org.geolatte.geom.Feature; 9 | import org.geolatte.geom.FeatureCollection; 10 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 11 | 12 | import java.io.IOException; 13 | import java.util.ArrayList; 14 | import java.util.Iterator; 15 | import java.util.List; 16 | 17 | 18 | @SuppressWarnings("rawtypes") 19 | public class FeatureCollectionDeserializer extends JsonDeserializer { 20 | final private FeatureDeserializer fDeserializer; 21 | public FeatureCollectionDeserializer(CoordinateReferenceSystem defaultCrs, Settings settings) { 22 | this.fDeserializer = new FeatureDeserializer(defaultCrs, settings); 23 | } 24 | 25 | @Override 26 | @SuppressWarnings("unchecked") 27 | public FeatureCollection deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { 28 | ObjectCodec oc = jsonParser.getCodec(); 29 | JsonNode root = oc.readTree(jsonParser); 30 | JsonNode featureNds = root.get("features"); 31 | List> features = new ArrayList<>(); 32 | for (Iterator it = featureNds.elements(); it.hasNext(); ) { 33 | JsonNode fNode = it.next(); 34 | features.add(fDeserializer.readFeature(oc, fNode)); 35 | } 36 | return (GeoJsonFeatureCollection)new GeoJsonFeatureCollection(features); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /json/src/main/java/org/geolatte/geom/json/FeatureCollectionSerializer.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.databind.JsonSerializer; 5 | import com.fasterxml.jackson.databind.SerializerProvider; 6 | import org.geolatte.geom.Box; 7 | import org.geolatte.geom.Feature; 8 | import org.geolatte.geom.FeatureCollection; 9 | import org.geolatte.geom.Position; 10 | 11 | import java.io.IOException; 12 | 13 | public class FeatureCollectionSerializer

extends JsonSerializer> { 14 | 15 | private final Settings settings; 16 | 17 | FeatureCollectionSerializer(Settings settings) { 18 | this.settings = settings; 19 | } 20 | 21 | @Override 22 | public void serialize(FeatureCollection featureColl, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { 23 | gen.writeStartObject(); 24 | gen.writeStringField("type", FeatureCollection.TYPE); 25 | Box box = featureColl.getBbox(); 26 | if (box != null && !box.isEmpty() && settings.isSet(Setting.SERIALIZE_FEATURE_COLLECTION_BBOX)) { 27 | gen.writeFieldName("bbox"); 28 | gen.writeObject(featureColl.getBbox()); 29 | } 30 | gen.writeArrayFieldStart("features"); 31 | for (Feature f : featureColl.getFeatures()) { 32 | gen.writeObject(f); 33 | } 34 | gen.writeEndArray(); 35 | gen.writeEndObject(); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /json/src/main/java/org/geolatte/geom/json/FeatureSerializer.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.databind.JsonSerializer; 5 | import com.fasterxml.jackson.databind.SerializerProvider; 6 | import org.geolatte.geom.Box; 7 | import org.geolatte.geom.Feature; 8 | import org.geolatte.geom.Position; 9 | 10 | import java.io.IOException; 11 | 12 | public class FeatureSerializer

extends JsonSerializer> { 13 | 14 | private final Settings settings; 15 | 16 | public FeatureSerializer(Settings settings) { 17 | this.settings = settings; 18 | } 19 | 20 | @Override 21 | public void serialize(Feature feature, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { 22 | gen.writeStartObject(); 23 | gen.writeStringField("type", Feature.TYPE); 24 | if (feature.getId() != null) { 25 | gen.writeFieldName("id"); 26 | gen.writeObject(feature.getId()); 27 | } 28 | Box box = feature.getBbox(); 29 | if (box != null && !box.isEmpty() && settings.isSet(Setting.SERIALIZE_FEATURE_BBOX)) { 30 | gen.writeFieldName("bbox"); 31 | gen.writeObject(box); 32 | } 33 | gen.writeFieldName("geometry"); 34 | gen.writeObject(feature.getGeometry()); 35 | gen.writeFieldName("properties"); 36 | gen.writeObject(feature.getProperties()); 37 | gen.writeEndObject(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /json/src/main/java/org/geolatte/geom/json/GeoJsonProcessingException.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | 5 | /** 6 | * Created by Karel Maesen, Geovise BVBA on 08/09/17. 7 | */ 8 | public class GeoJsonProcessingException extends JsonProcessingException { 9 | 10 | GeoJsonProcessingException(String msg) { 11 | super(msg); 12 | } 13 | 14 | GeoJsonProcessingException(Throwable cause) { 15 | super(cause); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /json/src/main/java/org/geolatte/geom/json/Setting.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 08/09/17. 5 | */ 6 | public enum Setting { 7 | 8 | /** 9 | * Force the JSON strings to the CRS set as default for the {@code GeometryModule}. 10 | * 11 | *

This ignores the CRS identifier present in the JSON object.

12 | * @deprecated Use IGNORE_CRS 13 | */ 14 | @Deprecated 15 | FORCE_DEFAULT_CRS_DIMENSION(false), 16 | 17 | /** 18 | * Ignore the CRS component during deserialization, if present 19 | */ 20 | IGNORE_CRS(false), 21 | /** 22 | * Suppresses the serialization of CRS property 23 | */ 24 | SUPPRESS_CRS_SERIALIZATION(false), 25 | 26 | /** 27 | * Serialize the CRS as a URN, rather than the traditional AUTH:CODE format. 28 | */ 29 | SERIALIZE_CRS_AS_URN(false), 30 | 31 | /** 32 | * Serialized a BBOX for a FeatureCollection 33 | */ 34 | SERIALIZE_FEATURE_COLLECTION_BBOX(false), 35 | 36 | /** 37 | * Serialize a BBOX for a feature 38 | */ 39 | SERIALIZE_FEATURE_BBOX(false); 40 | 41 | private boolean setByDefault; 42 | 43 | Setting(boolean isSetByDefault) { 44 | this.setByDefault = isSetByDefault; 45 | } 46 | 47 | public boolean isSetByDefault() { 48 | return this.setByDefault; 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /json/src/main/java/org/geolatte/geom/json/Settings.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * Created by Karel Maesen, Geovise BVBA on 08/09/17. 8 | */ 9 | //TODO -- Replace by Builder pattern so that the behavior is immutable after creation of the module 10 | class Settings { 11 | 12 | private final Map overrides = new HashMap(); 13 | 14 | public boolean isSet(Setting setting) { 15 | Boolean override = overrides.get(setting); 16 | return override == null ? setting.isSetByDefault() : override; 17 | } 18 | 19 | 20 | public void override(Setting setting, boolean value) { 21 | if(setting.isSetByDefault() != value) { 22 | overrides.put(setting, value); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/CrsDynamicegistrationTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import org.geolatte.geom.G3D; 4 | import org.geolatte.geom.Point; 5 | import org.junit.Test; 6 | 7 | import java.io.IOException; 8 | 9 | import static org.geolatte.geom.builder.DSL.g; 10 | import static org.geolatte.geom.builder.DSL.point; 11 | import static org.geolatte.geom.json.Crss.wgs3D; 12 | import static org.geolatte.geom.json.GeoJsonStrings.pointText3D; 13 | import static org.junit.Assert.assertEquals; 14 | import static org.junit.Assert.assertSame; 15 | 16 | /** 17 | * Unit test to verify that an extended CRS is created only once, and then reused for all subsequent deserializations 18 | * Created by Karel Maesen, Geovise BVBA on 12/09/2018. 19 | */ 20 | public class CrsDynamicegistrationTest extends GeoJsonTest { 21 | 22 | @Test 23 | public void testDeserializePointText3D() throws IOException { 24 | 25 | Point pnt1 = mapper.readValue(pointText3D, Point.class); 26 | Point pnt2 = mapper.readValue(pointText3D, Point.class); 27 | 28 | assertSame(pnt1.getCoordinateReferenceSystem(), pnt2.getCoordinateReferenceSystem()); 29 | } 30 | 31 | 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/Crss.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import org.geolatte.geom.*; 4 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 5 | import org.geolatte.geom.crs.CrsRegistry; 6 | import org.geolatte.geom.crs.LinearUnit; 7 | 8 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.*; 9 | 10 | /** 11 | * Created by Karel Maesen, Geovise BVBA on 09/09/17. 12 | */ 13 | public class Crss { 14 | 15 | 16 | static CoordinateReferenceSystem wgs3D = addVerticalSystem(WGS84, G3D.class, LinearUnit.METER); 17 | static CoordinateReferenceSystem wgs2DM = addLinearSystem(WGS84, G2DM.class, LinearUnit.METER); 18 | static CoordinateReferenceSystem wgs3DM = addLinearSystem(wgs3D, G3DM.class, LinearUnit.METER); 19 | static CoordinateReferenceSystem lambert72 = CrsRegistry.getProjectedCoordinateReferenceSystemForEPSG(31370); 20 | static CoordinateReferenceSystem lambert72Z = addVerticalSystem(lambert72, C3D.class, LinearUnit.METER); 21 | static CoordinateReferenceSystem lambert72ZM = addLinearSystem(lambert72Z, C3DM.class, LinearUnit.METER); 22 | } 23 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/ForceCrsToDefaultTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.geolatte.geom.*; 5 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 6 | import org.geolatte.geom.crs.LinearUnit; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | 11 | import static org.geolatte.geom.builder.DSL.g; 12 | import static org.geolatte.geom.builder.DSL.point; 13 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 14 | import static org.geolatte.geom.json.GeoJsonStrings.pointText3DM; 15 | import static org.geolatte.geom.json.GeoJsonStrings.pointTextWithUrnCrs; 16 | import static org.junit.Assert.assertEquals; 17 | 18 | /** 19 | * Created by Karel Maesen, Geovise BVBA on 14/02/2020. 20 | */ 21 | public class ForceCrsToDefaultTest extends GeoJsonTest { 22 | 23 | @Test 24 | public void test() throws IOException { 25 | 26 | ObjectMapper mapper = createMapper(Setting.FORCE_DEFAULT_CRS_DIMENSION, true); 27 | Point pnt = point(WGS84, g(1, 2)); 28 | assertEquals(pnt, mapper.readValue( pointTextWithUrnCrs, Geometry.class )); 29 | } 30 | 31 | @Test 32 | public void test3DM() throws IOException { 33 | ObjectMapper mapper = createMapper(Setting.FORCE_DEFAULT_CRS_DIMENSION, true); 34 | Point pnt = point(WGS84, g(1, 2)); 35 | assertEquals(pnt, mapper.readValue( pointText3DM, Geometry.class )); 36 | } 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/GeoJsonTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.geolatte.geom.Position; 5 | import org.geolatte.geom.crs.CoordinateReferenceSystem; 6 | import org.junit.Before; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * Created by Karel Maesen, Geovise BVBA on 09/09/17. 12 | */ 13 | abstract public class GeoJsonTest { 14 | 15 | ObjectMapper mapper; 16 | 17 | @Before 18 | public void setUp() { 19 | mapper = new ObjectMapper(); 20 | mapper.registerModule(new GeolatteGeomModule()); 21 | } 22 | 23 | public ObjectMapper createMapper(Map features) { 24 | GeolatteGeomModule module = new GeolatteGeomModule(); 25 | features.forEach((f, v) -> module.set(f, v)); 26 | mapper = new ObjectMapper(); 27 | mapper.registerModule(module); 28 | return mapper; 29 | } 30 | 31 | public ObjectMapper createMapper(Setting setting, boolean value) { 32 | GeolatteGeomModule module = new GeolatteGeomModule(); 33 | module.set(setting, value); 34 | mapper = new ObjectMapper(); 35 | mapper.registerModule(module); 36 | return mapper; 37 | } 38 | 39 | public

ObjectMapper createMapper(CoordinateReferenceSystem

crs, Setting f, boolean isSet) { 40 | mapper = new ObjectMapper(); 41 | GeolatteGeomModule module = new GeolatteGeomModule(crs); 42 | module.set(f, isSet); 43 | mapper.registerModule(module); 44 | return mapper; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/GeometryDeserializationTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import org.geolatte.geom.Geometry; 4 | import org.junit.Test; 5 | 6 | import java.io.IOException; 7 | 8 | import static org.geolatte.geom.builder.DSL.*; 9 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 10 | import static org.geolatte.geom.json.Crss.lambert72ZM; 11 | import static org.geolatte.geom.json.GeoJsonStrings.multiLineString; 12 | import static org.geolatte.geom.json.GeoJsonStrings.pointTextWithCrs34D; 13 | import static org.junit.Assert.assertEquals; 14 | 15 | /** 16 | * Created by Karel Maesen, Geovise BVBA on 17/09/17. 17 | */ 18 | public class GeometryDeserializationTest extends GeoJsonTest { 19 | 20 | @Test 21 | public void testDeserializeML() throws IOException { 22 | Geometry rec = mapper.readValue(multiLineString, Geometry.class); 23 | Geometry expected = multilinestring( 24 | linestring(WGS84, g(1, 1), g(1, 2)), 25 | linestring(WGS84, g(3, 4), g(5, 6)) 26 | ); 27 | assertEquals(expected, rec); 28 | } 29 | 30 | @Test 31 | public void testDeserializePoint() throws IOException { 32 | Geometry rec = mapper.readValue(pointTextWithCrs34D, Geometry.class); 33 | Geometry expected = point(lambert72ZM, c(1,2,3,4)); 34 | assertEquals(expected, rec); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/IgnoreCrsTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.geolatte.geom.Geometry; 5 | import org.geolatte.geom.Point; 6 | import org.junit.Test; 7 | 8 | import java.io.IOException; 9 | 10 | import static org.geolatte.geom.builder.DSL.*; 11 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 12 | import static org.geolatte.geom.json.GeoJsonStrings.pointTextWithUrnCrs; 13 | import static org.junit.Assert.assertEquals; 14 | 15 | /** 16 | * Created by Karel Maesen, Geovise BVBA on 14/02/2020. 17 | */ 18 | public class IgnoreCrsTest extends GeoJsonTest{ 19 | 20 | @Test 21 | public void testSrializePointWithCrsInUrnFormat() throws IOException { 22 | 23 | ObjectMapper mapper = createMapper(Setting.IGNORE_CRS, true); 24 | Point pnt = point(WGS84, g(1, 2)); 25 | assertEquals(pnt, mapper.readValue( pointTextWithUrnCrs, Geometry.class )); 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/LineStringSerializationTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import org.geolatte.geom.LineString; 6 | import org.junit.Test; 7 | 8 | import static org.geolatte.geom.builder.DSL.*; 9 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 10 | import static org.geolatte.geom.json.Setting.SUPPRESS_CRS_SERIALIZATION; 11 | import static org.geolatte.geom.json.GeoJsonStrings.*; 12 | import static org.junit.Assert.assertEquals; 13 | 14 | /** 15 | * Created by Karel Maesen, Geovise BVBA on 09/09/17. 16 | */ 17 | public class LineStringSerializationTest extends GeoJsonTest { 18 | 19 | 20 | @Test 21 | public void testSerializeEmpty() throws JsonProcessingException { 22 | 23 | ObjectMapper mapper = createMapper(SUPPRESS_CRS_SERIALIZATION, true); 24 | LineString ln = new LineString(WGS84); 25 | String rec = mapper.writeValueAsString(ln); 26 | assertEquals(emptyLineString,rec) ; 27 | } 28 | 29 | @Test 30 | public void testSerializeSimple() throws JsonProcessingException { 31 | 32 | ObjectMapper mapper = createMapper(SUPPRESS_CRS_SERIALIZATION, true); 33 | LineString ln = linestring(WGS84, g(1, 2), g(3, 4)); 34 | String rec = mapper.writeValueAsString(ln); 35 | assertEquals(simpleLineString,rec) ; 36 | } 37 | 38 | @Test 39 | public void testSerializeWithCRS() throws JsonProcessingException { 40 | LineString ln = linestring(Crss.lambert72, c(1, 2), c(3, 4)); 41 | String rec = mapper.writeValueAsString(ln); 42 | assertEquals(lineStringWithCrs,rec) ; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/MultiLineStringDeserializationTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import org.geolatte.geom.MultiLineString; 4 | import org.junit.Test; 5 | 6 | import java.io.IOException; 7 | 8 | import static org.geolatte.geom.builder.DSL.*; 9 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 10 | import static org.geolatte.geom.json.GeoJsonStrings.*; 11 | import static org.junit.Assert.assertEquals; 12 | 13 | /** 14 | * Created by Karel Maesen, Geovise BVBA on 11/09/17. 15 | */ 16 | public class MultiLineStringDeserializationTest extends GeoJsonTest { 17 | 18 | @Test 19 | public void testDeserializeEmpty() throws IOException { 20 | MultiLineString rec = mapper.readValue(emptyMultiLineString, MultiLineString.class); 21 | MultiLineString expected = new MultiLineString<>(WGS84); 22 | assertEquals(expected, rec); 23 | } 24 | 25 | @Test 26 | public void testDeserializeSimple() throws IOException { 27 | MultiLineString rec = mapper.readValue(multiLineString, MultiLineString.class); 28 | MultiLineString expected = multilinestring( 29 | linestring(WGS84, g(1, 1), g(1, 2)), 30 | linestring(WGS84, g(3, 4), g(5, 6)) 31 | ); 32 | assertEquals(expected, rec); 33 | } 34 | 35 | @Test 36 | public void testDeserializeWithCRS() throws IOException { 37 | MultiLineString rec = mapper.readValue(multiLineStringWithCrs, MultiLineString.class); 38 | MultiLineString expected = multilinestring( 39 | linestring(Crss.lambert72, c(1, 1), c(1, 2)), 40 | linestring(Crss.lambert72, c(3, 4), c(5, 6)) 41 | ); 42 | assertEquals(expected, rec); 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/MultiPointDeserializationTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import org.geolatte.geom.MultiPoint; 4 | import org.junit.Test; 5 | 6 | import java.io.IOException; 7 | 8 | import static org.geolatte.geom.builder.DSL.*; 9 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 10 | import static org.geolatte.geom.json.GeoJsonStrings.*; 11 | import static org.junit.Assert.assertEquals; 12 | 13 | /** 14 | * Created by Karel Maesen, Geovise BVBA on 11/09/17. 15 | */ 16 | public class MultiPointDeserializationTest extends GeoJsonTest { 17 | 18 | @Test 19 | public void testDeserializeEmpty() throws IOException { 20 | MultiPoint rec = mapper.readValue(emptyMultiPoint,MultiPoint.class); 21 | MultiPoint expected = new MultiPoint(WGS84); 22 | assertEquals(expected, rec); 23 | } 24 | 25 | @Test 26 | public void testDeserializeSimple() throws IOException { 27 | MultiPoint rec = mapper.readValue(multiPoint,MultiPoint.class); 28 | MultiPoint expected = multipoint(WGS84, g(1, 2), g(3, 4)); 29 | 30 | assertEquals(expected, rec); 31 | } 32 | 33 | @Test 34 | public void testDeserializeWithCRS() throws IOException { 35 | MultiPoint rec = mapper.readValue(multiPointWithCrs,MultiPoint.class); 36 | MultiPoint expected = multipoint(Crss.lambert72, c(1, 2), c(3, 4)); 37 | 38 | assertEquals(expected, rec); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/MultiPointSerializationTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import org.geolatte.geom.MultiPoint; 6 | import org.junit.Test; 7 | 8 | import static org.geolatte.geom.builder.DSL.*; 9 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 10 | import static org.geolatte.geom.json.Setting.SUPPRESS_CRS_SERIALIZATION; 11 | import static org.geolatte.geom.json.GeoJsonStrings.*; 12 | import static org.junit.Assert.assertEquals; 13 | 14 | /** 15 | * Created by Karel Maesen, Geovise BVBA on 11/09/17. 16 | */ 17 | public class MultiPointSerializationTest extends GeoJsonTest { 18 | 19 | 20 | @Test 21 | public void testSerializeEmpty() throws JsonProcessingException { 22 | 23 | ObjectMapper mapper = createMapper(SUPPRESS_CRS_SERIALIZATION, true); 24 | MultiPoint mp = multipoint(WGS84); 25 | String rec = mapper.writeValueAsString(mp); 26 | assertEquals(emptyMultiPoint, rec); 27 | } 28 | 29 | @Test 30 | public void testSerializeSimple() throws JsonProcessingException { 31 | 32 | ObjectMapper mapper = createMapper(SUPPRESS_CRS_SERIALIZATION, true); 33 | MultiPoint mp = multipoint(WGS84, g(1, 2), g(3, 4)); 34 | String rec = mapper.writeValueAsString(mp); 35 | assertEquals(multiPoint, rec); 36 | } 37 | 38 | @Test 39 | public void testSerializeWithCRS() throws JsonProcessingException { 40 | MultiPoint mp = multipoint(Crss.lambert72, c(1, 2), c(3, 4)); 41 | String rec = mapper.writeValueAsString(mp); 42 | assertEquals(multiPointWithCrs, rec); 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/PolygonDeserializerTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import org.geolatte.geom.Polygon; 4 | import org.junit.Test; 5 | 6 | import java.io.IOException; 7 | 8 | import static org.geolatte.geom.builder.DSL.*; 9 | import static org.geolatte.geom.builder.DSL.polygon; 10 | import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84; 11 | import static org.geolatte.geom.json.GeoJsonStrings.*; 12 | import static org.geolatte.geom.json.GeoJsonStrings.polygon; 13 | import static org.junit.Assert.assertEquals; 14 | 15 | /** 16 | * Created by Karel Maesen, Geovise BVBA on 09/09/17. 17 | */ 18 | public class PolygonDeserializerTest extends GeoJsonTest { 19 | 20 | @Test 21 | public void testEmtpy() throws IOException { 22 | Polygon rec = mapper.readValue(emptyPolygon, Polygon.class); 23 | Polygon exp = new Polygon<>(WGS84); 24 | assertEquals(exp, rec); 25 | } 26 | 27 | 28 | @Test 29 | public void testDeserializeSimple() throws IOException { 30 | Polygon rec = mapper.readValue(polygon, Polygon.class); 31 | Polygon expected = polygon(WGS84, ring(g(1, 1), g(1, 2), g(2, 2), g(2, 1), g(1, 1))); 32 | assertEquals(expected, rec); 33 | } 34 | 35 | @Test 36 | public void testDeserializeWithCRS() throws IOException { 37 | Polygon rec = mapper.readValue(polygonWithCrs, Polygon.class); 38 | Polygon expected = polygon(Crss.lambert72, ring(c(1, 1), c(1, 2), c(2, 2), c(2, 1), c(1, 1))); 39 | assertEquals(expected, rec); 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /json/src/test/java/org/geolatte/geom/json/UrnCrsSupportTest.java: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.json; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.geolatte.geom.Point; 5 | import org.junit.Test; 6 | 7 | import java.io.IOException; 8 | 9 | import static org.geolatte.geom.builder.DSL.c; 10 | import static org.geolatte.geom.builder.DSL.point; 11 | import static org.geolatte.geom.json.Crss.lambert72; 12 | import static org.geolatte.geom.json.GeoJsonStrings.pointTextWithUrnCrs; 13 | import static org.junit.Assert.assertEquals; 14 | 15 | /** 16 | * Created by Karel Maesen, Geovise BVBA on 17/09/17. 17 | */ 18 | public class UrnCrsSupportTest extends GeoJsonTest { 19 | 20 | @Test 21 | public void testSrializePointWithCrsInUrnFormat() throws IOException { 22 | 23 | ObjectMapper mapper = createMapper(Setting.SERIALIZE_CRS_AS_URN, true); 24 | Point pnt = point(lambert72, c(1, 2)); 25 | assertEquals(pointTextWithUrnCrs, mapper.writeValueAsString(pnt)); 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /scala/.scalafmt.conf: -------------------------------------------------------------------------------- 1 | version=2.0.0-RC5 2 | align = more // For pretty alignment. 3 | maxColumn = 100 // For my wide 30" display. 4 | -------------------------------------------------------------------------------- /scala/play-json-28/src/test/scala/org/geolatte/geom/playjson/GeoJsonStringGenerator.scala: -------------------------------------------------------------------------------- 1 | package org.geolatte.geom.playjson 2 | 3 | /** 4 | * Created by Karel Maesen, Geovise BVBA on 24/09/2018. 5 | */ 6 | object GeoJsonStringGenerator { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /scala/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.3.3 2 | -------------------------------------------------------------------------------- /scala/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.0") 2 | 3 | // supports release in maven central 4 | addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.2") 5 | addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1") 6 | 7 | --------------------------------------------------------------------------------