Updates, Cleanup and preparation for a pull request.
Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/d305f9da Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/d305f9da Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/d305f9da Branch: refs/heads/ramtej-fb/spatial.queries Commit: d305f9dabdbf3cb024b20645796a20acba46788b Parents: 9d71ec3 Author: jj <[email protected]> Authored: Thu Jan 15 18:26:34 2015 +0100 Committer: jj <[email protected]> Committed: Thu Jan 15 18:26:34 2015 +0100 ---------------------------------------------------------------------- build.gradle | 9 +- .../java/org/qi4j/api/geometry/TFeature.java | 6 + .../qi4j/api/geometry/internal/Coordinate.java | 6 - .../geometry/internal/GeometryCollections.java | 6 +- .../qi4j/api/geometry/internal/TGeometry.java | 2 +- .../predicate/ST_DisjointSpecification.java | 12 +- .../predicate/ST_IntersectsSpecification.java | 12 +- .../test/indexing/AbstractAnyQueryTest.java | 2 +- extensions/indexing-elasticsearch/build.gradle | 8 +- .../elasticsearch/ElasticSearchIndexer.java | 6 +- .../spatial/ElasticSearchSpatialIndexer.java | 4 +- .../functions/convert/ST_GeometryFromText.java | 2 +- .../AbstractElasticSearchSpatialFunction.java | 4 +- .../spatial/ElasticSearchSpatialBench.java | 23 +- .../ElasticSearchSpatialClusterQueryTest.java | 132 + ...chSpatialQueryTestUsingGeoPointIndexing.java | 4 +- ...chSpatialQueryTestUsingGeoShapeIndexing.java | 3 +- ...earchSpatialQueryTestUsingUsingDefaults.java | 2 +- ...SearchSpatialRegressionQueryClusterTest.java | 3 +- .../resources/ElasticSearchBenchmark.properties | 30 + .../src/test/resources/RIAKBenchmark.properties | 1 + .../spatial/assembly/TGeometryAssembler.java | 80 + .../spatial/conversions/TConversions.java | 30 + .../spatial/conversions/from/FromHelper.java | 58 + .../conversions/from/GeoJsonFromConverter.java | 204 + .../from/TGeometryFromConverter.java | 38 + .../conversions/from/WKTFromConverter.java | 226 + .../conversions/to/GeoJsonToConverter.java | 66 + .../conversions/to/Spatial4JToConverter.java | 117 + .../conversions/to/TGeometryToConverter.java | 46 + .../spatial/conversions/to/ToHelper.java | 62 + .../geometry/geojson/types/Coordinates.java | 14 - .../spatial/incubator/geometry/topojson/_._ | 0 .../spatial/parser/geojson/GeoJSONParser.java | 51 - .../spatial/projection/ProjectionsRegistry.java | 75 + .../transformations/TTransformations.java | 31 + .../transformations/fromto/FromHelper.java | 41 + .../transformations/fromto/ToHelper.java | 150 + .../spatial/projections/ProjectionService.java | 117 - .../spatial/projections/Projections.java | 29 - .../projections/ProjectionsTransformation.java | 133 - .../transformations/GeoJsonTransformator.java | 17 - .../geojson/GeoJSONParserV2.java | 23 - .../geojson/internal/ParserBuilder.java | 78 - .../geojson/internal/TransformationBuilder.java | 140 - .../spatial/v2/assembly/TGeometryAssembler.java | 70 - .../spatial/v2/conversions/TConversions.java | 16 - .../spatial/v2/conversions/from/FromHelper.java | 42 - .../conversions/from/GeoJsonFromConverter.java | 159 - .../from/TGeometryFromConverter.java | 22 - .../v2/conversions/from/WKTFromConverter.java | 210 - .../v2/conversions/to/GeoJsonToConverter.java | 52 - .../v2/conversions/to/Spatial4JToConverter.java | 101 - .../v2/conversions/to/TGeometryToConverter.java | 28 - .../spatial/v2/conversions/to/ToHelper.java | 44 - .../v2/projections/ProjectionsRegistry.java | 61 - .../v2/projections/SpatialRefSysManager.java | 37 - .../spatial/v2/transformations/FromHelper.java | 27 - .../v2/transformations/TTransformations.java | 14 - .../spatial/v2/transformations/ToHelper.java | 168 - .../spatial/SpatialRefSysManagerTest.java | 93 - .../conversions/ConversionsFromWktTest.java | 33 + .../ConversionsWithProjectionsTest.java | 86 + .../ConvertFromGeoJsonToTGeometryTest.java | 179 + .../spatial/geojson/SimpleGeoJsonTest.java | 108 - .../parser/geojson/SimpleGeoJSONParser.java | 303 - .../projections/ProjectionServiceTest.java | 109 - .../ProjectionsTransformationTest.java | 56 - .../repository/SimpleSpatialRepositoryTest.java | 164 - .../spatial/topo/GeoJSONSpec20080616.java | 16 +- .../spatial/topo/GeoJSONSwissLakes2013.java | 71 +- .../transformations/TransformationsTest.java | 74 + .../v2/conversions/ConversionsFromWktTest.java | 49 - .../spatial/v2/conversions/ConversionsTest.java | 117 - .../ConversionsWithProjectionsTest.java | 55 - .../ConvertFromGeoJsonToTGeometry.java | 65 - .../v2/transformations/TransformationsTest.java | 105 - .../topo/geojson/swiss/FeatureCollection.json | 109 +- .../resources/topo/geojson/swiss/ch-lakes.json | 6124 +++++++++++++++++- .../topo/topojson/swiss/ag-municipalities.json | 1 - .../topo/topojson/swiss/ai-municipalities.json | 1 - .../topo/topojson/swiss/ar-municipalities.json | 1 - .../topo/topojson/swiss/be-municipalities.json | 1 - .../topo/topojson/swiss/bl-municipalities.json | 1 - .../topo/topojson/swiss/bs-municipalities.json | 1 - .../topo/topojson/swiss/ch-cantons.json | 1 - .../topo/topojson/swiss/ch-country.json | 1 - .../topo/topojson/swiss/ch-districts.json | 1 - .../topo/topojson/swiss/ch-lakes.jj.json | 200 - .../resources/topo/topojson/swiss/ch-lakes.json | 37 - .../topo/topojson/swiss/ch-municipalities.json | 11 - .../test/resources/topo/topojson/swiss/ch.json | 1 - .../topo/topojson/swiss/fr-municipalities.json | 1 - .../topo/topojson/swiss/ge-municipalities.json | 1 - .../topo/topojson/swiss/gl-municipalities.json | 1 - .../topo/topojson/swiss/gr-municipalities.json | 1 - .../topo/topojson/swiss/ju-municipalities.json | 1 - .../topo/topojson/swiss/lu-municipalities.json | 1 - .../topo/topojson/swiss/ne-municipalities.json | 1 - .../topo/topojson/swiss/nw-municipalities.json | 1 - .../topo/topojson/swiss/ow-municipalities.json | 1 - .../topo/topojson/swiss/sg-municipalities.json | 1 - .../topo/topojson/swiss/sh-municipalities.json | 1 - .../topo/topojson/swiss/so-municipalities.json | 1 - .../topo/topojson/swiss/sz-municipalities.json | 1 - .../topo/topojson/swiss/tg-municipalities.json | 1 - .../topo/topojson/swiss/ti-municipalities.json | 1 - .../topo/topojson/swiss/ur-municipalities.json | 1 - .../topo/topojson/swiss/vd-municipalities.json | 1 - .../topo/topojson/swiss/vs-municipalities.json | 1 - .../topo/topojson/swiss/zg-municipalities.json | 1 - .../topo/topojson/swiss/zh-municipalities.json | 1 - .../openstreetmap/model/test/TestOSMModel.java | 1 - 113 files changed, 8099 insertions(+), 3250 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index c8fdcd3..660f461 100644 --- a/build.gradle +++ b/build.gradle @@ -175,7 +175,7 @@ allprojects { if( ext.javaDir.isDirectory() || ext.scalaDir.isDirectory() || ext.testJavaDir.isDirectory() || ext.testScalaDir.isDirectory() ) { - apply plugin: 'jacoco' + // apply plugin: 'jacoco' apply plugin: 'osgi' apply plugin: VersionClass apply plugin: AsciidocBuildInfo @@ -340,10 +340,10 @@ test { // Jacoco configurations { - jacoco + //jacoco } dependencies { - jacoco 'org.jacoco:org.jacoco.ant:0.7.1.201405082137' + // jacoco 'org.jacoco:org.jacoco.ant:0.7.1.201405082137' } // Generate a global code codeverage report task coverageReport { @@ -356,6 +356,7 @@ task coverageReport { def toolsProjects = coveredProjects.findAll { p -> p.name.startsWith( 'org.qi4j.tool' ) } def tutoProjects = coveredProjects.findAll { p -> p.name.startsWith( 'org.qi4j.tuto' ) } def samplesProjects = coveredProjects.findAll { p -> p.name.startsWith( 'org.qi4j.sample' ) } + /** ant { taskdef name:'jacocoreport', classname: 'org.jacoco.ant.ReportTask', classpath: configurations.jacoco.asPath mkdir dir: outputPath @@ -396,9 +397,11 @@ task coverageReport { } inputs.dir coveredProjects.collect { p -> "${p.buildDir.path}/jacoco" } outputs.dir outputPath + */ } + // Build the whole SDK public Javadoc task javadocs( type: Javadoc ) { http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/core/api/src/main/java/org/qi4j/api/geometry/TFeature.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TFeature.java b/core/api/src/main/java/org/qi4j/api/geometry/TFeature.java index f899d0b..cf983e9 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/TFeature.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TFeature.java @@ -15,6 +15,7 @@ package org.qi4j.api.geometry; import org.qi4j.api.common.Optional; +import org.qi4j.api.geometry.internal.Coordinate; import org.qi4j.api.geometry.internal.TGeometry; import org.qi4j.api.geometry.internal.TLinearRing; import org.qi4j.api.injection.scope.Structure; @@ -90,6 +91,11 @@ public interface TFeature extends TGeometry { return (self.geometry() == null) || (self.geometry().get() == null) || (self.geometry().get().isEmpty()) ? true : false; } + + public Coordinate[] getCoordinates() + { + return self.geometry().get().getCoordinates(); + } public int getNumPoints() { return isEmpty() ? 0 : self.geometry().get().getNumPoints(); } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/core/api/src/main/java/org/qi4j/api/geometry/internal/Coordinate.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/Coordinate.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/Coordinate.java index c986788..ac01539 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/Coordinate.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/internal/Coordinate.java @@ -39,22 +39,16 @@ public interface Coordinate extends Comparable, ValueComposite, TGeometryRoot { Property<List<Double>> coordinate(); Coordinate of(); - Coordinate of(double x, double y, double z); - Coordinate of(double... coordinates); Coordinate x(double x); - Coordinate y(double y); - Coordinate z(double z); double x(); - double y(); - double z(); double getOrdinate(int ordinateIndex); http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/core/api/src/main/java/org/qi4j/api/geometry/internal/GeometryCollections.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/GeometryCollections.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/GeometryCollections.java index e99831c..48b0537 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/GeometryCollections.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/internal/GeometryCollections.java @@ -72,9 +72,9 @@ public interface GeometryCollections extends TGeometry { int k = -1; for (int i = 0; i < self.getNumGeometries(); i++) { Coordinate[] childCoordinates = self.geometries().get().get(i).getCoordinates(); - for (int j = 0; j < childCoordinates.length; j++) { - k++; - coordinates[k] = childCoordinates[j]; + for (int j = 0; j < childCoordinates.length; j++) { + k++; + coordinates[k] = childCoordinates[j]; } } return coordinates; http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/core/api/src/main/java/org/qi4j/api/geometry/internal/TGeometry.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/TGeometry.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/TGeometry.java index 5138596..18c273c 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/TGeometry.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/internal/TGeometry.java @@ -93,7 +93,7 @@ public interface TGeometry extends TGeometryRoot { } public Coordinate[] getCoordinates() { - return null; + throw new RuntimeException("Should never be called"); } public boolean isEmpty() { http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_DisjointSpecification.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_DisjointSpecification.java b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_DisjointSpecification.java index b3c95a3..3d85281 100644 --- a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_DisjointSpecification.java +++ b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_DisjointSpecification.java @@ -47,6 +47,16 @@ public class ST_DisjointSpecification<T extends TGeometry> @Override public String toString() { - return "ST_DisjointSpecification"; // property.toString() + " is within " + value.toString(); + StringBuffer spec = new StringBuffer(); + spec.append("ST_DISJOINT").append("( ").append(property.toString()).append(" IS NOT WITHIN "); + spec.append(param.toString()); + + if (distance > 0) + { + spec.append(" WITH RADIUS ").append(distance).append(" ").append(unit); + } + + spec.append(" ) "); + return spec.toString(); } } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_IntersectsSpecification.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_IntersectsSpecification.java b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_IntersectsSpecification.java index b7f40c4..90cb3ab 100644 --- a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_IntersectsSpecification.java +++ b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_IntersectsSpecification.java @@ -48,6 +48,16 @@ public class ST_IntersectsSpecification<T extends TGeometry> @Override public String toString() { - return "ST_IntersectsSpecification"; // property.toString() + " is within " + value.toString(); + StringBuffer spec = new StringBuffer(); + spec.append("ST_INTERSECTS").append("( ").append(property.toString()).append(" INTERSECTS "); + spec.append(param.toString()); + + if (distance > 0) + { + spec.append(" WITH RADIUS ").append(distance).append(" ").append(unit); + } + + spec.append(" ) "); + return spec.toString(); } } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractAnyQueryTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractAnyQueryTest.java b/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractAnyQueryTest.java index 1c5ba2e..21d701d 100644 --- a/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractAnyQueryTest.java +++ b/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractAnyQueryTest.java @@ -79,7 +79,7 @@ public class AbstractAnyQueryTest TGeometry tGeometry = module.forMixin(TGeometry.class).declareDefaults(); tGeometry.CRS().set(CRS_EPSG_4326); - new EntityTestAssembler().assemble( module ); + // new EntityTestAssembler().assemble( module ); } @Override http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/build.gradle ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/build.gradle b/extensions/indexing-elasticsearch/build.gradle index 525bf4e..883ef33 100644 --- a/extensions/indexing-elasticsearch/build.gradle +++ b/extensions/indexing-elasticsearch/build.gradle @@ -9,7 +9,8 @@ dependencies { compile project(":org.qi4j.libraries:org.qi4j.library.spatial") compile project(":org.qi4j.libraries:org.qi4j.library.sql") compile project(":org.qi4j.extensions:org.qi4j.extension.entitystore-sql") - compile(project(":org.qi4j.extensions:org.qi4j.extension.entitystore-riak")) + compile project(":org.qi4j.extensions:org.qi4j.extension.entitystore-riak") + compile project(":org.qi4j.extensions:org.qi4j.extension.valueserialization-orgjson") @@ -23,3 +24,8 @@ dependencies { } +// test { +// jacoco { +// enabled = false +// } +// } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java index e651ee3..0e7edd4 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java @@ -127,10 +127,10 @@ public interface ElasticSearchIndexer index( bulkBuilder, changedState.identity().identity(), updatedJson ); break; case NEW: - LOGGER.trace( "Creating Entity State in Index: {}", changedState ); + // LOGGER.trace( "Creating Entity State in Index: {}", changedState ); String newJson = toJSON(changedState, newStates, uow ); - System.out.println("#Will index: {} : " + newJson); - LOGGER.trace( "Will index: {}", newJson ); + // System.out.println("#Will index: {} : " + newJson); + // LOGGER.trace( "Will index: {}", newJson ); index( bulkBuilder, changedState.identity().identity(), newJson ); break; case LOADED: http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/ElasticSearchSpatialIndexer.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/ElasticSearchSpatialIndexer.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/ElasticSearchSpatialIndexer.java index e77e6fe..7fd7a2a 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/ElasticSearchSpatialIndexer.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/ElasticSearchSpatialIndexer.java @@ -28,7 +28,7 @@ import org.qi4j.index.elasticsearch.ElasticSearchIndexException; import org.qi4j.index.elasticsearch.ElasticSearchSupport; import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialConfiguration; import org.qi4j.index.elasticsearch.extensions.spatial.mappings.SpatialIndexMapper; -import org.qi4j.library.spatial.v2.projections.ProjectionsRegistry; +import org.qi4j.library.spatial.projection.ProjectionsRegistry; import java.util.HashMap; import java.util.ListIterator; @@ -36,7 +36,7 @@ import java.util.Map; import java.util.Stack; import static org.qi4j.index.elasticsearch.extensions.spatial.mappings.SpatialIndexMapper.IndexMappingCache; -import static org.qi4j.library.spatial.v2.transformations.TTransformations.Transform; +import static org.qi4j.library.spatial.projection.transformations.TTransformations.Transform; public final class ElasticSearchSpatialIndexer { http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/convert/ST_GeometryFromText.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/convert/ST_GeometryFromText.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/convert/ST_GeometryFromText.java index 04722c5..bd8fe6c 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/convert/ST_GeometryFromText.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/convert/ST_GeometryFromText.java @@ -23,7 +23,7 @@ import org.qi4j.spi.query.EntityFinderException; import java.util.Map; -import static org.qi4j.library.spatial.v2.conversions.TConversions.Convert; +import static org.qi4j.library.spatial.conversions.TConversions.Convert; public class ST_GeometryFromText extends AbstractElasticSearchSpatialFunction implements ConvertFinderSupport.ConvertSpecification { http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/internal/AbstractElasticSearchSpatialFunction.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/internal/AbstractElasticSearchSpatialFunction.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/internal/AbstractElasticSearchSpatialFunction.java index 523cac5..a5f6d79 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/internal/AbstractElasticSearchSpatialFunction.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/internal/AbstractElasticSearchSpatialFunction.java @@ -39,7 +39,7 @@ import org.qi4j.index.elasticsearch.ElasticSearchSupport; import org.qi4j.index.elasticsearch.extensions.spatial.ElasticSearchSpatialFinder; import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialConfiguration; import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialFunctionsSupportMatrix; -import org.qi4j.library.spatial.v2.projections.ProjectionsRegistry; +import org.qi4j.library.spatial.projection.ProjectionsRegistry; import org.qi4j.spi.query.EntityFinderException; import java.lang.reflect.Type; @@ -47,7 +47,7 @@ import java.util.Map; import static org.qi4j.api.geometry.TGeometryFactory.TPoint; import static org.qi4j.index.elasticsearch.extensions.spatial.mappings.SpatialIndexMapper.IndexMappingCache; -import static org.qi4j.library.spatial.v2.transformations.TTransformations.Transform; +import static org.qi4j.library.spatial.projection.transformations.TTransformations.Transform; /** http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialBench.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialBench.java b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialBench.java index 8a4a0fd..0ffa488 100644 --- a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialBench.java +++ b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialBench.java @@ -7,23 +7,19 @@ import org.junit.Test; import org.qi4j.api.common.Visibility; import org.qi4j.api.entity.EntityBuilder; import org.qi4j.api.geometry.TPoint; -import org.qi4j.api.query.Query; import org.qi4j.api.unitofwork.UnitOfWork; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly; import org.qi4j.entitystore.riak.RiakHttpMapEntityStoreAssembler; -import org.qi4j.entitystore.sql.assembly.DerbySQLEntityStoreAssembler; import org.qi4j.index.elasticsearch.ElasticSearchConfiguration; import org.qi4j.index.elasticsearch.assembly.ESClusterIndexQueryAssembler; -import org.qi4j.index.elasticsearch.assembly.ESFilesystemIndexQueryAssembler; import org.qi4j.index.elasticsearch.extension.spatial.utils.RandomPoint; import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialConfiguration; import org.qi4j.library.fileconfig.FileConfigurationOverride; import org.qi4j.library.fileconfig.FileConfigurationService; -import org.qi4j.library.spatial.v2.assembly.TGeometryAssembler; -import org.qi4j.library.sql.assembly.DataSourceAssembler; -import org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler; +import org.qi4j.library.spatial.assembly.TGeometryAssembler; import org.qi4j.test.EntityTestAssembler; +import org.qi4j.test.indexing.AbstractAnyQueryTest; import org.qi4j.test.indexing.AbstractSpatialRegressionTest; import org.qi4j.test.util.DelTreeAfter; import org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler; @@ -59,8 +55,6 @@ public class ElasticSearchSpatialBench // Geometry support new TGeometryAssembler().assemble(module); - - // Config module ModuleAssembly config = module.layer().module( "config" ); new EntityTestAssembler().assemble( config ); @@ -72,11 +66,10 @@ public class ElasticSearchSpatialBench SpatialConfiguration.ProjectionSupport.class). visibleIn(Visibility.application); - // Index/Query new ESClusterIndexQueryAssembler(). withConfig(config, Visibility.layer). - identifiedBy("ElasticSearchGeoShapeIndexing"). + identifiedBy("ElasticSearchBenchmark"). assemble(module); ElasticSearchConfiguration esConfig = config.forMixin(ElasticSearchConfiguration.class).declareDefaults(); esConfig.indexNonAggregatedAssociations().set(Boolean.TRUE); @@ -98,11 +91,11 @@ public class ElasticSearchSpatialBench new EntityTestAssembler().assemble( configRiak ); new OrgJsonValueSerializationAssembler().assemble( module ); // START SNIPPET: assembly - new RiakHttpMapEntityStoreAssembler().withConfig( configRiak, Visibility.layer ).assemble( module ); + new RiakHttpMapEntityStoreAssembler().identifiedBy("RIAKBenchmark").withConfig(configRiak, Visibility.layer ).assemble( module ); /** +++ */ } - @Test + // @Test public void test() throws Exception { @@ -144,8 +137,8 @@ public class ElasticSearchSpatialBench // System.out.println("spherical " + xy[0] + " " + xy[1] ); long start = System.currentTimeMillis(); - for (int j = 0; j < 1000; j++) { - + for (int j = 0; j < 1000; j++) + { System.out.println("--> " + j); UnitOfWork unitOfWork = module.newUnitOfWork(); @@ -164,8 +157,6 @@ public class ElasticSearchSpatialBench } long end = System.currentTimeMillis(); - - System.out.println("Duration " + (end - start)); } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialClusterQueryTest.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialClusterQueryTest.java b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialClusterQueryTest.java new file mode 100644 index 0000000..4252da5 --- /dev/null +++ b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialClusterQueryTest.java @@ -0,0 +1,132 @@ +package org.qi4j.index.elasticsearch.extension.spatial; + +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.qi4j.api.common.Visibility; +import org.qi4j.api.query.QueryExecutionException; +import org.qi4j.bootstrap.AssemblyException; +import org.qi4j.bootstrap.ModuleAssembly; +import org.qi4j.entitystore.riak.RiakHttpMapEntityStoreAssembler; +import org.qi4j.index.elasticsearch.ElasticSearchConfiguration; +import org.qi4j.index.elasticsearch.assembly.ESClusterIndexQueryAssembler; +import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialConfiguration; +import org.qi4j.library.fileconfig.FileConfigurationOverride; +import org.qi4j.library.fileconfig.FileConfigurationService; +import org.qi4j.library.spatial.assembly.TGeometryAssembler; +import org.qi4j.spi.query.EntityFinderException; +import org.qi4j.test.EntityTestAssembler; +import org.qi4j.test.indexing.AbstractSpatialRegressionTest; +import org.qi4j.test.util.DelTreeAfter; +import org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler; + +import java.io.File; + +import static org.qi4j.test.util.Assume.assumeNoIbmJdk; + +/** + * Created by jj on 21.12.14. + */ +public class ElasticSearchSpatialClusterQueryTest + extends AbstractSpatialRegressionTest +{ + private static final File DATA_DIR = new File( "build/tmp/es-spatial-query-test" ); + @Rule + public final DelTreeAfter delTreeAfter = new DelTreeAfter( DATA_DIR ); + + @BeforeClass + public static void beforeClass_IBMJDK() + { + assumeNoIbmJdk(); + } + + + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + super.assemble( module ); + + // Geometry support + new TGeometryAssembler().assemble(module); + + + + // Config module + ModuleAssembly config = module.layer().module( "config" ); + new EntityTestAssembler().assemble( config ); + + config.values(SpatialConfiguration.Configuration.class, + SpatialConfiguration.FinderConfiguration.class, + SpatialConfiguration.IndexerConfiguration.class, + SpatialConfiguration.IndexingMethod.class, + SpatialConfiguration.ProjectionSupport.class). + visibleIn(Visibility.application); + + + // Index/Query + new ESClusterIndexQueryAssembler(). + withConfig(config, Visibility.layer). + identifiedBy("ElasticSearchBenchmark"). + assemble(module); + ElasticSearchConfiguration esConfig = config.forMixin(ElasticSearchConfiguration.class).declareDefaults(); + esConfig.indexNonAggregatedAssociations().set(Boolean.TRUE); + + // FileConfig + FileConfigurationOverride override = new FileConfigurationOverride(). + withData(new File(DATA_DIR, "qi4j-data")). + withLog(new File(DATA_DIR, "qi4j-logs")). + withTemporary(new File(DATA_DIR, "qi4j-temp")); + module.services(FileConfigurationService.class). + setMetaInfo(override); + + // In-Memory Entity Store + // new EntityTestAssembler().assemble( module ); + + + /** RIAK */ + ModuleAssembly configRiak = module.layer().module( "configRiak" ); + new EntityTestAssembler().assemble( configRiak ); + new OrgJsonValueSerializationAssembler().assemble( module ); + // START SNIPPET: assembly + new RiakHttpMapEntityStoreAssembler().withConfig( configRiak, Visibility.layer ).assemble( module ); + /** +++ */ + } + + + @Test(expected=QueryExecutionException.class) + public void script01c() + throws EntityFinderException + { + super.script01c(); // <- no orderBy() support for GeoShapes + } + + @Test(expected=QueryExecutionException.class) + public void script01d() + throws EntityFinderException + { + super.script01d(); // <- no orderBy() support for GeoShapes + } + + @Test(expected=QueryExecutionException.class) + public void script01e() + throws EntityFinderException + { + super.script01e(); // <- no orderBy() support for GeoShapes + } + + @Test(expected=QueryExecutionException.class) + public void script01f() + throws EntityFinderException + { + super.script01f(); // <- no orderBy() support for GeoShapes + } + + @Test(expected=QueryExecutionException.class) + public void script03c() + throws EntityFinderException + { + super.script03c(); // <- no orderBy() support for GeoShapes + } + +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingGeoPointIndexing.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingGeoPointIndexing.java b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingGeoPointIndexing.java index 6200b68..bd27bd9 100644 --- a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingGeoPointIndexing.java +++ b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingGeoPointIndexing.java @@ -15,11 +15,9 @@ package org.qi4j.index.elasticsearch.extension.spatial; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.qi4j.api.common.Visibility; -import org.qi4j.api.query.Query; import org.qi4j.api.query.QueryExecutionException; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly; @@ -28,7 +26,7 @@ import org.qi4j.index.elasticsearch.assembly.ESFilesystemIndexQueryAssembler; import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialConfiguration; import org.qi4j.library.fileconfig.FileConfigurationOverride; import org.qi4j.library.fileconfig.FileConfigurationService; -import org.qi4j.library.spatial.v2.assembly.TGeometryAssembler; +import org.qi4j.library.spatial.assembly.TGeometryAssembler; import org.qi4j.spi.query.EntityFinderException; import org.qi4j.test.EntityTestAssembler; import org.qi4j.test.indexing.AbstractSpatialRegressionTest; http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingGeoShapeIndexing.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingGeoShapeIndexing.java b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingGeoShapeIndexing.java index 6f227f1..8ac58b9 100644 --- a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingGeoShapeIndexing.java +++ b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingGeoShapeIndexing.java @@ -18,7 +18,6 @@ import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.qi4j.api.common.Visibility; -import org.qi4j.api.query.Query; import org.qi4j.api.query.QueryExecutionException; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly; @@ -27,7 +26,7 @@ import org.qi4j.index.elasticsearch.assembly.ESFilesystemIndexQueryAssembler; import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialConfiguration; import org.qi4j.library.fileconfig.FileConfigurationOverride; import org.qi4j.library.fileconfig.FileConfigurationService; -import org.qi4j.library.spatial.v2.assembly.TGeometryAssembler; +import org.qi4j.library.spatial.assembly.TGeometryAssembler; import org.qi4j.spi.query.EntityFinderException; import org.qi4j.test.EntityTestAssembler; import org.qi4j.test.indexing.AbstractSpatialRegressionTest; http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingUsingDefaults.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingUsingDefaults.java b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingUsingDefaults.java index f5a8337..1904139 100644 --- a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingUsingDefaults.java +++ b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialQueryTestUsingUsingDefaults.java @@ -26,7 +26,7 @@ import org.qi4j.index.elasticsearch.assembly.ESFilesystemIndexQueryAssembler; import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialConfiguration; import org.qi4j.library.fileconfig.FileConfigurationOverride; import org.qi4j.library.fileconfig.FileConfigurationService; -import org.qi4j.library.spatial.v2.assembly.TGeometryAssembler; +import org.qi4j.library.spatial.assembly.TGeometryAssembler; import org.qi4j.spi.query.EntityFinderException; import org.qi4j.test.EntityTestAssembler; import org.qi4j.test.indexing.AbstractSpatialRegressionTest; http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryClusterTest.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryClusterTest.java b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryClusterTest.java index d4ec9fe..7fd00bf 100644 --- a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryClusterTest.java +++ b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryClusterTest.java @@ -8,11 +8,10 @@ import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly; import org.qi4j.index.elasticsearch.ElasticSearchConfiguration; import org.qi4j.index.elasticsearch.assembly.ESClusterIndexQueryAssembler; -import org.qi4j.index.elasticsearch.assembly.ESFilesystemIndexQueryAssembler; import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialConfiguration; import org.qi4j.library.fileconfig.FileConfigurationOverride; import org.qi4j.library.fileconfig.FileConfigurationService; -import org.qi4j.library.spatial.v2.assembly.TGeometryAssembler; +import org.qi4j.library.spatial.assembly.TGeometryAssembler; import org.qi4j.test.EntityTestAssembler; import org.qi4j.test.indexing.AbstractSpatialRegressionTest; import org.qi4j.test.util.DelTreeAfter; http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchBenchmark.properties ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchBenchmark.properties b/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchBenchmark.properties new file mode 100644 index 0000000..dd67ab3 --- /dev/null +++ b/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchBenchmark.properties @@ -0,0 +1,30 @@ +nodes=localhost:9300 + +spatial = { \ + \ + Enabled : true, \ + \ + Indexer=\ + { \ + Method=\ + { \ + Type = "GEO_POINT", \ + Precision = 1m, \ + }, \ + Projection=\ + { \ + ConversionEnabled = true, \ + ConversionAccuracy = 2m, \ + }, \ + }, \ + \ + \ + Finder=\ + { \ + Projection=\ + { \ + ConversionEnabled = true, \ + ConversionAccuracy = 2m, \ + } \ + } \ + } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/extensions/indexing-elasticsearch/src/test/resources/RIAKBenchmark.properties ---------------------------------------------------------------------- diff --git a/extensions/indexing-elasticsearch/src/test/resources/RIAKBenchmark.properties b/extensions/indexing-elasticsearch/src/test/resources/RIAKBenchmark.properties new file mode 100644 index 0000000..94d160c --- /dev/null +++ b/extensions/indexing-elasticsearch/src/test/resources/RIAKBenchmark.properties @@ -0,0 +1 @@ +urls=http://localhost:8098/riak \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/assembly/TGeometryAssembler.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/assembly/TGeometryAssembler.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/assembly/TGeometryAssembler.java new file mode 100644 index 0000000..178d838 --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/assembly/TGeometryAssembler.java @@ -0,0 +1,80 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.assembly; + +import org.cts.crs.CRSException; +import org.cts.crs.CoordinateReferenceSystem; +import org.qi4j.api.geometry.*; +import org.qi4j.api.geometry.internal.Coordinate; +import org.qi4j.api.geometry.internal.TCircle; +import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.internal.TLinearRing; +import org.qi4j.bootstrap.Assemblers; +import org.qi4j.bootstrap.AssemblyException; +import org.qi4j.bootstrap.ModuleAssembly; +import org.qi4j.library.spatial.projection.ProjectionsRegistry; + +public class TGeometryAssembler + extends Assemblers.VisibilityIdentity<TGeometryAssembler> +{ + private static final String CRS_EPSG_4326 = "EPSG:4326"; + private static String DEFAULT_CRS = CRS_EPSG_4326; + + + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + // internal values + module.values(Coordinate.class, TLinearRing.class, TCircle.class, TGeometry.class); + // API values + module.values( + TCRS.class, + TPoint.class, + TMultiPoint.class, + TLineString.class, + TMultiLineString.class, + TPolygon.class, + TMultiPolygon.class, + TFeature.class, + TFeatureCollection.class); + + TGeometry tGeometry = module.forMixin(TGeometry.class).declareDefaults(); + tGeometry.CRS().set(DEFAULT_CRS); + } + + public TGeometryAssembler withCRS(String crs) throws AssemblyException + { + try + { + CoordinateReferenceSystem ref = new ProjectionsRegistry().getReferenceSystem(crs); + if (ref == null || ref.getCoordinateSystem() == null) + { + throw new AssemblyException("Projection CRS " + crs + " invalid."); + } + + } catch(CRSException _ex) + { + throw new AssemblyException("Projection CRS " + crs + " invalid.", _ex); + } + + DEFAULT_CRS = crs; + return this; + } +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/TConversions.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/TConversions.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/TConversions.java new file mode 100644 index 0000000..1037b2d --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/TConversions.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.conversions; + +import org.qi4j.api.structure.Module; +import org.qi4j.library.spatial.conversions.from.FromHelper; + +public class TConversions { + + public static FromHelper Convert(Module module) + { + return new FromHelper(module); + } +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/FromHelper.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/FromHelper.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/FromHelper.java new file mode 100644 index 0000000..3f1d399 --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/FromHelper.java @@ -0,0 +1,58 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.conversions.from; + +import org.geojson.GeoJsonObject; +import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.structure.Module; +import org.qi4j.library.spatial.conversions.to.ToHelper; + + +public class FromHelper { + + private Module module; + + public FromHelper(Module module) + { + this.module = module; + } + + public ToHelper from(TGeometry tGeometry) + { + return new ToHelper(module, new TGeometryFromConverter(module).convert(tGeometry)); + } + + public ToHelper from(GeoJsonObject geoJsonObject) + { + return new ToHelper(module, new GeoJsonFromConverter(module).convert(geoJsonObject)); + + } + + public ToHelper from(String wkt) throws Exception + { + return new ToHelper(module, new WKTFromConverter(module).convert(wkt, null)); + } + + public ToHelper from(String wkt, String crs) throws Exception + { + return new ToHelper(module, new WKTFromConverter(module).convert(wkt, crs)); + } + + private FromHelper() {} +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/GeoJsonFromConverter.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/GeoJsonFromConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/GeoJsonFromConverter.java new file mode 100644 index 0000000..a75f9e1 --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/GeoJsonFromConverter.java @@ -0,0 +1,204 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.conversions.from; + +import org.geojson.*; +import org.qi4j.api.geometry.*; +import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.internal.TLinearRing; +import org.qi4j.api.structure.Module; + +import java.util.List; + +import static org.qi4j.api.geometry.TGeometryFactory.*; +import static org.qi4j.api.geometry.TGeometryFactory.TLinearRing; + + +public class GeoJsonFromConverter { + + private Module module; + + public GeoJsonFromConverter(Module module) + { + this.module = module; + } + + public TGeometry convert(GeoJsonObject geojson) + + { + return transform(geojson); + } + + private TGeometry transform(GeoJsonObject geojson) + { + if (geojson instanceof Point) + { + return createTPoint((Point) geojson); + } + else if ( (geojson instanceof MultiPoint) && !(geojson instanceof LineString) ) + { + return createTMultiPoint((MultiPoint)geojson); + } + else if (geojson instanceof LineString) + { + return createTLineString((LineString)geojson); + } + else if (geojson instanceof MultiLineString) + { + return createTMultiLineString((MultiLineString)geojson); + } + else if (geojson instanceof Polygon) + { + return createTPolygon((Polygon) geojson); + } + else if (geojson instanceof MultiPolygon) + { + return createTMultiPolygon((MultiPolygon) geojson); + } + else if (geojson instanceof Feature) + { + return createTFeature((Feature)geojson); + } + else if (geojson instanceof FeatureCollection) + { + return createTFeatureCollection((FeatureCollection)geojson); + } + else throw new RuntimeException("Unknown GeoJSON type - " + geojson); + } + + + private TGeometry createTPoint(Point point) + { + return TPoint(module) + .x(point.getCoordinates().getLatitude()) + .y(point.getCoordinates().getLongitude()) + .z(point.getCoordinates().getAltitude()) + .geometry(); + } + private TGeometry createTMultiPoint(MultiPoint multiPoint) + { + TMultiPoint tMultiPoint = TMultiPoint(module).geometry(); + for (LngLatAlt xyz : multiPoint.getCoordinates() ) + { + tMultiPoint.of + ( + TPoint(module) + .x(xyz.getLatitude()) + .y(xyz.getLongitude()) + .z(xyz.getAltitude()) + .geometry() + ); + } + return tMultiPoint; + } + + private TGeometry createTLineString(LineString lineString) + { + TLineString tLineString = TLineString(module).of().geometry(); + + for (LngLatAlt xyz : lineString.getCoordinates() ) { + tLineString.of( + TPoint(module) + .x(xyz.getLatitude()) + .y(xyz.getLongitude()) + .z(xyz.getAltitude()) + .geometry() + ); + } + return tLineString; + } + + private TGeometry createTMultiLineString(MultiLineString multiLineString) + { + TMultiLineString tMultiLineString = TMultiLineString(module).of().geometry(); + for (List<LngLatAlt> coordinates : multiLineString. getCoordinates()) + { + tMultiLineString.of(getLine(coordinates)); + } + return tMultiLineString; + } + + private TGeometry createTPolygon(Polygon polygon) + { + TPolygon tPolygon; + TLinearRing ring = getRing((polygon).getExteriorRing()); + if (!ring.isValid()) + throw new RuntimeException("Polygon shell not valid"); + else + tPolygon = TPolygon(module).shell(ring).geometry(); + for (int i = 0; i < (polygon).getInteriorRings().size(); i++) + { + tPolygon.withHoles(getRing((polygon).getInteriorRings().get(i))); + } + return tPolygon; + } + + private TGeometry createTMultiPolygon(MultiPolygon multiPolygon) + { + TMultiPolygon tMultiPolygon = TMultiPolygon(module).of().geometry(); + for (List<List<LngLatAlt>> polygons : multiPolygon.getCoordinates() ) + { + for (List<LngLatAlt> polygon : polygons ) + { + tMultiPolygon.of(TPolygon(module).shell(getRing(polygon)).geometry()); + } + } + return tMultiPolygon; + } + + private TGeometry createTFeature(Feature feature) + { + return TFeature(module).of(new GeoJsonFromConverter(module).transform(feature.getGeometry())).geometry(); + } + + private TGeometry createTFeatureCollection(FeatureCollection featurecollection) + { + TFeatureCollection tFeatureCollection = TFeatureCollection(module).of().geometry(); + for (Feature feature : featurecollection.getFeatures()) + { + tFeatureCollection.of((TFeature)createTFeature(feature)); + } + return tFeatureCollection; + } + + private TLineString getLine(List<LngLatAlt> coordinates) + { + TLineString tLineString = TLineString(module).of().geometry(); + for (LngLatAlt xyz :coordinates ) + { + tLineString.yx(xyz.getLatitude(), xyz.getLongitude()); + } + return tLineString; + } + private TLinearRing getRing(List<LngLatAlt> coordinates) + { + + TLinearRing tLinearRing = TLinearRing(module).of().geometry(); + for (LngLatAlt xyz :coordinates ) { + tLinearRing.yx(xyz.getLatitude(), xyz.getLongitude()); + } + + if (!tLinearRing.isClosed()) + { + tLinearRing.of(tLinearRing.getStartPoint()); // hack here - we are closing the ring, of not closed. + } + + return tLinearRing; + } +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/TGeometryFromConverter.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/TGeometryFromConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/TGeometryFromConverter.java new file mode 100644 index 0000000..2c66b42 --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/TGeometryFromConverter.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.conversions.from; + +import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.structure.Module; + + +public class TGeometryFromConverter { + + private Module module; + + public TGeometryFromConverter(Module module) + { + this.module = module; + } + + public TGeometry convert(TGeometry tGeometry) + { + return tGeometry; + } +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/WKTFromConverter.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/WKTFromConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/WKTFromConverter.java new file mode 100644 index 0000000..169c311 --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/from/WKTFromConverter.java @@ -0,0 +1,226 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.conversions.from; + +import com.spatial4j.core.context.SpatialContext; +import com.spatial4j.core.context.jts.JtsSpatialContextFactory; +import com.spatial4j.core.io.jts.JtsWKTReaderShapeParser; +import com.spatial4j.core.io.jts.JtsWktShapeParser; +import com.spatial4j.core.shape.Circle; +import com.spatial4j.core.shape.Point; +import com.spatial4j.core.shape.Shape; +import com.spatial4j.core.shape.jts.JtsGeometry; +import com.spatial4j.core.shape.jts.JtsPoint; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.LineString; +import com.vividsolutions.jts.geom.MultiPolygon; +import com.vividsolutions.jts.geom.Polygon; +import org.qi4j.api.geometry.TPoint; +import org.qi4j.api.geometry.TPolygon; +import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.internal.TLinearRing; +import org.qi4j.api.structure.Module; +import org.qi4j.api.value.ValueBuilder; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +import static org.qi4j.api.geometry.TGeometryFactory.TPoint; + + +public class WKTFromConverter { + + + final SpatialContext ctx; + { + JtsSpatialContextFactory factory = new JtsSpatialContextFactory(); + factory.srid = 4326; + factory.datelineRule = JtsWktShapeParser.DatelineRule.ccwRect; + factory.wktShapeParserClass = JtsWKTReaderShapeParser.class; + ctx = factory.newSpatialContext(); + } + + + + private Module module; + + public WKTFromConverter(Module module) + { + this.module = module; + } + + public TGeometry convert(String wkt, String crs) throws ParseException + { + + Shape sNoDL = ctx.readShapeFromWkt(wkt); + + + if (!sNoDL.hasArea()) { + System.out.println("Its a JtsGeometry " + ((JtsPoint) sNoDL).getGeom().getGeometryType()); + return buildPoint(module,sNoDL); + } else { + System.out.println("Its a JtsGeometry " + ((JtsGeometry) sNoDL).getGeom().getGeometryType()); + + Geometry jtsGeometry = ((JtsGeometry) sNoDL).getGeom(); + + if (jtsGeometry instanceof Polygon) { + System.out.println("Polygon"); + return buildPolygon(module,sNoDL); + } + else if (jtsGeometry instanceof MultiPolygon) { + System.out.println("MultiPolygon"); + } + else if (jtsGeometry instanceof LineString) { + System.out.println("LineString"); + } + + + + + } + + + + if (sNoDL instanceof Point) + { + + // ctx.makeCircle(0,0,0).getBoundingBox(). + // System.out.println("Shape is point "); + + ValueBuilder<TPoint> builder = module.newValueBuilder(TPoint.class); + + builder.prototype().x(((Point) sNoDL).getX()).y(((Point) sNoDL).getY()); +/** + builder.prototype().of + ( + module.newValueBuilder(Coordinate.class).prototype().of(((Point) sNoDL).getX()), //x + module.newValueBuilder(Coordinate.class).prototype().of(((Point) sNoDL).getY()) //y + ); + */ + return builder.newInstance(); + + +// ValueBuilder<TGeomPoint> builder = module.newValueBuilder( TGeomPoint.class ); +// TGeomPoint proto = builder.prototype(); +// List<Double> coordinates = new ArrayList<Double>(); +//// +// Double lat = 3.138722; // 3.138722;// Double.parseDouble(query.nextToken()); +// Double lon = 101.386849; // Double.parseDouble(query.nextToken()); +//// +//// +// coordinates.add(3.138722); +// coordinates.add(101.386849); +// proto.coordinates().set(coordinates); +// +// return builder.newInstance(); + + } else + + if (sNoDL instanceof Circle) { + + } else + { + System.out.println("Its a shape"); + if (sNoDL.hasArea() ) System.out.println("Shape With area.."); + + if (sNoDL instanceof JtsGeometry) { + + System.out.println("Its a JtsGeometry " + ((JtsGeometry) sNoDL).getGeom().getGeometryType()); + // ((JtsGeometry) sNoDL).getGeom() + } + + } + + System.out.println("sNoDL " + sNoDL); + + return null; +} + + + private TPoint buildPoint(Module module, Shape sNoDL) { + ValueBuilder<TPoint> builder = module.newValueBuilder(TPoint.class); + + + builder.prototype().x(((Point) sNoDL).getX()).y(((Point) sNoDL).getY()); + /** + builder.prototype().of + ( + module.newValueBuilder(Coordinate.class).prototype().of(((Point) sNoDL).getX()), //x + module.newValueBuilder(Coordinate.class).prototype().of(((Point) sNoDL).getY()) //y + ); + */ + + return builder.newInstance(); + } + + private TPolygon buildPolygon(Module module, Shape sNoDL) { + + Geometry jtsGeometry = ((JtsGeometry) sNoDL).getGeom(); + Polygon jtsPolygon = (Polygon)jtsGeometry; + + // Polygon jtsPolygon = ((JtsGeometry) sNoDL).getGeom(); + + // Polygon jtsPolygon = (Polygon)sNoDL; + + System.out.println("Get Coordinates " + jtsPolygon.getExteriorRing().getCoordinates() ); + + com.vividsolutions.jts.geom.Coordinate[] coordinates = jtsPolygon.getExteriorRing().getCoordinates(); + + ValueBuilder<TPolygon> polygonBuilder = module.newValueBuilder(TPolygon.class); + ValueBuilder<TLinearRing> tLinearRingBuilder = module.newValueBuilder(TLinearRing.class); + + List<TPoint> points = new ArrayList<>(); + for (int i = 0; i < coordinates.length; i++) { +/** + TPoint point = module.newValueBuilder(TPoint.class).prototype().of + ( + module.newValueBuilder(Coordinate.class).prototype().of( coordinates[i].x), //x + module.newValueBuilder(Coordinate.class).prototype().of( coordinates[i].y) //y + );*/ + points.add + ( + TPoint(module) + + .x(coordinates[i].x) + .y(coordinates[i].y).geometry() + ); + } + tLinearRingBuilder.prototype().of(points); + + // tLinearRingBuilder.prototype().of(points); + // tLinearRingBuilder.prototype().type() + + // TLinearRing tLinearRing = tLinearRingBuilder.newInstance(); + // System.out.println("tLinearRing .." + tLinearRing); + + + ValueBuilder<TPolygon> builder = module.newValueBuilder(TPolygon.class); + + builder.prototype().of + ( + // tLinearRingBuilder.newInstance().of(points) + tLinearRingBuilder.newInstance() + ); + + return builder.newInstance(); + } + + +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/GeoJsonToConverter.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/GeoJsonToConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/GeoJsonToConverter.java new file mode 100644 index 0000000..595431a --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/GeoJsonToConverter.java @@ -0,0 +1,66 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.conversions.to; + +import org.geojson.GeoJsonObject; +import org.geojson.Point; +import org.qi4j.api.geometry.TPoint; +import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.structure.Module; + + +public class GeoJsonToConverter { + + + private Module module; + + public GeoJsonToConverter(Module module) + { + this.module = module; + } + + public GeoJsonObject convert(TGeometry intemediate) + { + return transform(intemediate); + } + + private GeoJsonObject transform(TGeometry intemediate) + { + + switch(intemediate.getType()) + { + case POINT : return buildPoint((TPoint)intemediate); + case MULTIPOINT : return null; + case LINESTRING : return null; + case MULTILINESTRING : return null; + case POLYGON : return null; + case MULTIPOLYGON : return null; + case FEATURE : return null; + case FEATURECOLLECTION : return null; + default : throw new RuntimeException("Unknown TGeometry Type."); + } + + } + + private Point buildPoint(TPoint point) + { + return new Point(point.x(), point.y()); + } + +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/Spatial4JToConverter.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/Spatial4JToConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/Spatial4JToConverter.java new file mode 100644 index 0000000..e60f30c --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/Spatial4JToConverter.java @@ -0,0 +1,117 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.conversions.to; + +import com.spatial4j.core.context.SpatialContext; +import com.spatial4j.core.context.jts.JtsSpatialContext; +import com.spatial4j.core.context.jts.JtsSpatialContextFactory; +import com.spatial4j.core.io.jts.JtsWKTReaderShapeParser; +import com.spatial4j.core.io.jts.JtsWktShapeParser; +import com.spatial4j.core.shape.Circle; +import com.spatial4j.core.shape.Shape; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.util.GeometricShapeFactory; +import org.geojson.GeoJsonObject; +import org.geojson.Point; +import org.qi4j.api.geometry.TPoint; +import org.qi4j.api.geometry.internal.TCircle; +import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.structure.Module; + + +public class Spatial4JToConverter { + + // http://code.google.com/p/shape-metrics/source/browse/trunk/src/main/java/edu/psu/geovista/ian/utils/Circle.java?r=2 + + final SpatialContext ctx; + { + JtsSpatialContextFactory factory = new JtsSpatialContextFactory(); + factory.srid = 4326; + factory.datelineRule = JtsWktShapeParser.DatelineRule.ccwRect; + factory.wktShapeParserClass = JtsWKTReaderShapeParser.class; + ctx = factory.newSpatialContext(); + } + + public static final double DATELINE = 180; + public static final JtsSpatialContext SPATIAL_CONTEXT = JtsSpatialContext.GEO; + public static final GeometryFactory FACTORY = SPATIAL_CONTEXT.getGeometryFactory(); + public static final GeometricShapeFactory SHAPE_FACTORY = new GeometricShapeFactory(); + + protected final boolean multiPolygonMayOverlap = false; + protected final boolean autoValidateJtsGeometry = true; + protected final boolean autoIndexJtsGeometry = true; + + protected final boolean wrapdateline = SPATIAL_CONTEXT.isGeo(); + + + private Module module; + + public Spatial4JToConverter(Module module) + { + this.module = module; + } + + public GeoJsonObject convert(TGeometry intemediate) + { + // return transform(intemediate); + return null; + } + + private Shape transform(TGeometry intermediate) + { + + switch(intermediate.getType()) + { + case POINT : return null; // return newPoint((TPoint) intemediate); + case MULTIPOINT : return null; + case LINESTRING : return null; + case MULTILINESTRING : return null; + case POLYGON : return null; + case MULTIPOLYGON : return null; + case FEATURE : return null; + case FEATURECOLLECTION : return null; + } + + if (intermediate instanceof TCircle) + { + return newCircle((TCircle)intermediate); + } + else + return null; + + + } + + private Point newPoint(TPoint point) + { + // SPATIAL_CONTEXT.makeCircle(0,0,0). + + // SHAPE_FACTORY.set + + System.out.println("point.x() " + point.x()); + System.out.println("point.y() " + point.y()); + return new Point(point.x(), point.y()); + } + + private Circle newCircle(TCircle circle) + { + return ctx.makeCircle(circle.getCentre().x(), circle.getCentre().y(), circle.radius().get()); + } + +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/TGeometryToConverter.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/TGeometryToConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/TGeometryToConverter.java new file mode 100644 index 0000000..01eaeed --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/TGeometryToConverter.java @@ -0,0 +1,46 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.conversions.to; + +import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.structure.Module; + +/** + * Created by jj on 04.12.14. + */ +public class TGeometryToConverter { + + private Module module; + + public TGeometryToConverter(Module module) + { + this.module = module; + } + + public TGeometry convert (TGeometry tGeometry, String CRS) + { + return tGeometry; + } + + public TGeometry convert(TGeometry tGeometry) + { + return convert(tGeometry, tGeometry.getCRS()); + } + +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/ToHelper.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/ToHelper.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/ToHelper.java new file mode 100644 index 0000000..ae9916b --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/ToHelper.java @@ -0,0 +1,62 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.conversions.to; + +import org.geojson.GeoJsonObject; +import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.structure.Module; + +import static org.qi4j.library.spatial.projection.transformations.TTransformations.Transform; + +/** + * Created by jj on 04.12.14. + */ +public class ToHelper { + + private Module module; + private TGeometry intermediate; + + public ToHelper(Module module, TGeometry intermediate) + { + this.module = module; + this.intermediate = intermediate; + } + + public TGeometry toTGeometry() + { + return new TGeometryToConverter(module).convert(intermediate); + } + + public TGeometry toTGeometry(String CRS) throws Exception + { + if (!intermediate.getCRS().equalsIgnoreCase(CRS)) + Transform(module).from(intermediate).to(CRS) ; + + return new TGeometryToConverter(module).convert(intermediate, CRS); + } + + + + public GeoJsonObject toGeoJson() + { + return new GeoJsonToConverter(module).convert(intermediate); + } + + private ToHelper() {} +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/incubator/geometry/geojson/types/Coordinates.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/incubator/geometry/geojson/types/Coordinates.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/incubator/geometry/geojson/types/Coordinates.java deleted file mode 100644 index b35d4ce..0000000 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/incubator/geometry/geojson/types/Coordinates.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.qi4j.library.spatial.incubator.geometry.geojson.types; - -import org.qi4j.api.property.Property; - -import java.util.List; - -/** - * Created by jakes on 2/7/14. - */ -public interface Coordinates { - - Property<List<List<Double>>> coordinates(); - -} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/incubator/geometry/topojson/_._ ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/incubator/geometry/topojson/_._ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/incubator/geometry/topojson/_._ deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/parser/geojson/GeoJSONParser.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/parser/geojson/GeoJSONParser.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/parser/geojson/GeoJSONParser.java deleted file mode 100644 index e2f19cd..0000000 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/parser/geojson/GeoJSONParser.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.qi4j.library.spatial.parser.geojson; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.geojson.Feature; -import org.geojson.FeatureCollection; -import org.geojson.Point; - -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.util.Iterator; - - -/** - * Created by jakes on 2/23/14. - */ -public class GeoJSONParser { - - public void parse() throws Exception { - - BufferedInputStream inputstream = new BufferedInputStream(new FileInputStream("/home/jakes/Projects/QI4J/Spatial/qi4j-sdk/libraries/spatial/src/test/resources/topo/geojson/germany/bavaria.neustadt.geojson")); - - FeatureCollection featureCollection = - new ObjectMapper().readValue(inputstream, FeatureCollection.class); - - System.out.println("Found num of features " + featureCollection.getFeatures().size()); - - Iterator<Feature> features = featureCollection.getFeatures().iterator(); - - while (features.hasNext()) { - Feature feature = features.next(); - - if (feature.getGeometry() instanceof Point) { - System.out.println("Processing Ppint"); - } - - - System.out.println(feature.getGeometry().getClass() ); - } - - } - - public static void main(String [] args) - { - GeoJSONParser geoJSONParser = new GeoJSONParser(); - try { - geoJSONParser.parse(); - } catch(Exception _ex) { - _ex.printStackTrace(); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/ProjectionsRegistry.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/ProjectionsRegistry.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/ProjectionsRegistry.java new file mode 100644 index 0000000..e82592f --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/ProjectionsRegistry.java @@ -0,0 +1,75 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.projection; + +import org.cts.CRSFactory; +import org.cts.crs.CRSException; +import org.cts.crs.CoordinateReferenceSystem; +import org.cts.registry.*; + +import java.util.Set; + + +public class ProjectionsRegistry { + + protected static CRSFactory cRSFactory = new CRSFactory(); + + + static { + RegistryManager registryManager = cRSFactory.getRegistryManager(); + registryManager.addRegistry(new IGNFRegistry()); + registryManager.addRegistry(new EPSGRegistry()); + registryManager.addRegistry(new ESRIRegistry()); + registryManager.addRegistry(new Nad27Registry()); + registryManager.addRegistry(new Nad83Registry()); + registryManager.addRegistry(new worldRegistry()); + } + + + public Set<String> getSupportedSRID(String registryName) throws RegistryException + { + return cRSFactory.getSupportedCodes(registryName); + } + + // EPSG, IGNF, ESRI + public Set<String> getSupportedRegistryCodes(String registryName) throws RegistryException { + return cRSFactory.getRegistryManager().getRegistry(registryName).getSupportedCodes(); + } + + public String[] dumpRegistries() { + return cRSFactory.getRegistryManager().getRegistryNames(); + } + + public CoordinateReferenceSystem getCRS(String wkt) { + try { + return cRSFactory.getCRS(wkt); + } catch(CRSException _ex) + { + _ex.printStackTrace(); + return null; + } + } + + + public CoordinateReferenceSystem getReferenceSystem(String csName) throws CRSException + { + return cRSFactory.getCRS(csName); + } + +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/TTransformations.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/TTransformations.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/TTransformations.java new file mode 100644 index 0000000..1235a27 --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/TTransformations.java @@ -0,0 +1,31 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.projection.transformations; + +import org.qi4j.api.structure.Module; +import org.qi4j.library.spatial.projection.transformations.fromto.FromHelper; + + +public class TTransformations { + + public static FromHelper Transform(Module module) + { + return new FromHelper(module); + } +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d305f9da/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/fromto/FromHelper.java ---------------------------------------------------------------------- diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/fromto/FromHelper.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/fromto/FromHelper.java new file mode 100644 index 0000000..e1fa78a --- /dev/null +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/fromto/FromHelper.java @@ -0,0 +1,41 @@ +/* + * Copyright 2014 Jiri Jetmar. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.spatial.projection.transformations.fromto; + +import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.structure.Module; +import org.qi4j.library.spatial.conversions.from.TGeometryFromConverter; + + +public class FromHelper { + + private Module module; + + public FromHelper(Module module) + { + this.module = module; + } + + private FromHelper() {} + + public ToHelper from(TGeometry tGeometry) + { + return new ToHelper(module, new TGeometryFromConverter(module).convert(tGeometry)); + } +}
