Moving things around to keep the Core API as small as possible. Also considering if it is possible to make the Query Fluent API extensible, so that these kind of things would actually only be an Extension and not require additions to Core API. WARNING; may not compile at the moment.
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/Coordinate.java b/core/api/src/main/java/org/qi4j/api/geometry/Coordinate.java new file mode 100644 index 0000000..07f2425 --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/geometry/Coordinate.java
@@ -0,0 +1,210 @@ +/* + * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. + * + * 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.api.geometry; + +import java.util.ArrayList; +import java.util.List; +import org.qi4j.api.common.Optional; +import org.qi4j.api.injection.scope.This; +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.property.Property; +import org.qi4j.api.value.ValueComposite; + +/** + * Represents one single n-Dimensional coordinate in the n-Dimensional "space" + */ + +@Mixins( Coordinate.Mixin.class ) +public interface Coordinate extends Comparable, ValueComposite +{ + + public static final int X = 0; + public static final int Y = 1; + public static final int Z = 2; + + // single coordinate store + @Optional + 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 ); + + int compareTo( Object o ); + + double[] source(); + + public abstract class Mixin implements Coordinate + { + + List<Double> EMPTY = new ArrayList<>( X + Y + Z ); + @This + Coordinate self; + + private void init() + { + if( isEmpty() ) + { + EMPTY.add( new Double( 0.0 ) ); + EMPTY.add( new Double( 0.0 ) ); + EMPTY.add( new Double( 0.0 ) ); + + self.coordinate().set( EMPTY ); + } + } + + private boolean isEmpty() + { + return ( self.coordinate() == null ) || ( self.coordinate().get() == null ) || ( self.coordinate() + .get() + .isEmpty() ) ? true : false; + } + + public Coordinate of() + { + return self.of( 0.0d, 0.0d, 0.0d ); + } + + public Coordinate of( double x, double y, double z ) + { + init(); + self.x( x ); + self.y( y ); + self.z( z ); + return self; + } + + public double x() + { + return getOrdinate( X ); + } + + public double y() + { + return getOrdinate( Y ); + } + + public double z() + { + return getOrdinate( Z ); + } + + public Coordinate x( double x ) + { + init(); + if( !Double.isNaN( x ) && !Double.isInfinite( x ) ) + { + self.coordinate().get().set( X, x ); + } + return self; + } + + public Coordinate y( double y ) + { + init(); + if( !Double.isNaN( y ) && !Double.isInfinite( y ) ) + { + self.coordinate().get().set( Y, y ); + } + return self; + } + + public Coordinate z( double z ) + { + init(); + if( !Double.isNaN( z ) && !Double.isInfinite( z ) ) + { + self.coordinate().get().set( Z, z ); + } + return self; + } + + public int compareTo( Object o ) + { + Coordinate other = (Coordinate) o; + if( self.coordinate().get().get( X ) < other.coordinate().get().get( X ) ) + { + return -1; + } + if( self.coordinate().get().get( X ) > other.coordinate().get().get( X ) ) + { + return 1; + } + if( self.coordinate().get().get( Y ) < other.coordinate().get().get( Y ) ) + { + return -1; + } + if( self.coordinate().get().get( Y ) > other.coordinate().get().get( Y ) ) + { + return 1; + } + return 0; + } + + public double getOrdinate( int ordinateIndex ) + { + switch( ordinateIndex ) + { + case X: + return self.coordinate().get().get( X ); + case Y: + return self.coordinate().get().get( Y ); + case Z: + return self.coordinate().get().get( Z ); + } + throw new IllegalArgumentException( "Invalid ordinate index: " + ordinateIndex ); + } + + public double[] source() + { + double[] source = new double[ X + Y + Z ]; + source[ X ] = getOrdinate( X ); + source[ Y ] = getOrdinate( Y ); + source[ Z ] = getOrdinate( Z ); + return source; + } + + public Coordinate of( double... coordinates ) + { + List<Double> l = new ArrayList<Double>( coordinates.length ); + for( double xyzn : coordinates ) + { + // only values that makes "sense" + if( !Double.isNaN( xyzn ) && !Double.isInfinite( xyzn ) ) + { + l.add( new Double( xyzn ) ); + } + } + self.coordinate().set( l ); + return self; + } + } +}
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/GeometryCollections.java similarity index 69% rename from core/api/src/main/java/org/qi4j/api/geometry/internal/GeometryCollections.java rename to core/api/src/main/java/org/qi4j/api/geometry/GeometryCollections.java index 7f9d5a8..8607187 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/GeometryCollections.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/GeometryCollections.java
@@ -12,21 +12,19 @@ * */ -package org.qi4j.api.geometry.internal; - -import org.qi4j.api.injection.scope.This; -import org.qi4j.api.property.Property; +package org.qi4j.api.geometry; import java.util.ArrayList; import java.util.List; - +import org.qi4j.api.injection.scope.This; +import org.qi4j.api.property.Property; public interface GeometryCollections extends TGeometry { Property<List<TGeometry>> geometries(); - TGeometry getGeometryN(int n); + TGeometry getGeometryN( int n ); int getNumGeometries(); @@ -38,21 +36,20 @@ @This GeometryCollections self; - protected void init() { - if (self.geometries().get() == null) + if( self.geometries().get() == null ) { List<TGeometry> geometries = new ArrayList<>(); - self.geometries().set(geometries); + self.geometries().set( geometries ); } } public boolean isEmpty() { - for (int i = 0; i < self.geometries().get().size(); i++) + for( int i = 0; i < self.geometries().get().size(); i++ ) { - if (!self.geometries().get().get(i).isEmpty()) + if( !self.geometries().get().get( i ).isEmpty() ) { return false; } @@ -65,21 +62,22 @@ return self.geometries().get().size(); } - public TGeometry getGeometryN(int n) + public TGeometry getGeometryN( int n ) { - return self.geometries().get().get(n); + return self.geometries().get().get( n ); } + public Coordinate[] getCoordinates() { - Coordinate[] coordinates = new Coordinate[self.getNumPoints()]; + Coordinate[] coordinates = new Coordinate[ self.getNumPoints() ]; int k = -1; - for (int i = 0; i < self.getNumGeometries(); i++) + for( int i = 0; i < self.getNumGeometries(); i++ ) { - Coordinate[] childCoordinates = self.geometries().get().get(i).getCoordinates(); - for (int j = 0; j < childCoordinates.length; j++) + Coordinate[] childCoordinates = self.geometries().get().get( i ).getCoordinates(); + for( int j = 0; j < childCoordinates.length; j++ ) { k++; - coordinates[k] = childCoordinates[j]; + coordinates[ k ] = childCoordinates[ j ]; } } return coordinates; @@ -88,13 +86,11 @@ public int getNumPoints() { int numPoints = 0; - for (int i = 0; i < self.geometries().get().size(); i++) + for( int i = 0; i < self.geometries().get().size(); i++ ) { - numPoints += self.geometries().get().get(i).getNumPoints(); + numPoints += self.geometries().get().get( i ).getNumPoints(); } return numPoints; } - } - }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TCRS.java b/core/api/src/main/java/org/qi4j/api/geometry/TCRS.java index 67c605c..663dfde 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/TCRS.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TCRS.java
@@ -21,11 +21,13 @@ import org.qi4j.api.structure.Module; import org.qi4j.api.value.ValueComposite; -@Mixins(TCRS.Mixin.class) +@Mixins( TCRS.Mixin.class ) public interface TCRS extends ValueComposite { Property<String> definition(); - TCRS of(String crs); + + TCRS of( String crs ); + String crs(); public abstract class Mixin implements TCRS @@ -35,9 +37,9 @@ @This TCRS self; - public TCRS of(String crs) + public TCRS of( String crs ) { - self.definition().set(crs); + self.definition().set( crs ); return self; }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TCircle.java b/core/api/src/main/java/org/qi4j/api/geometry/TCircle.java new file mode 100644 index 0000000..caf91bd --- /dev/null +++ b/core/api/src/main/java/org/qi4j/api/geometry/TCircle.java
@@ -0,0 +1,121 @@ +package org.qi4j.api.geometry; + +import org.qi4j.api.injection.scope.Structure; +import org.qi4j.api.injection.scope.This; +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.property.Property; +import org.qi4j.api.structure.Module; + +@Mixins( TCircle.Mixin.class ) +public interface TCircle extends TGeometry +{ + Property<TPoint> point(); + + Property<Double> radius(); + + TCircle of( TPoint point, double radius ); + + TCircle of( double x, double y, double radius ); + + TCircle of( TPoint point ); + + TCircle of(); + + TCircle yx( double y, double x ); + + TCircle yx( double y, double x, double radius ); + + TCircle radius( double r ); + + TPoint getCentre(); + + TPolygon polygonize( int numOfPoints ); + + public abstract class Mixin implements TCircle + { + @This + TCircle self; + + @Structure + Module module; + + public TCircle of() + { + return self; + } + + public TCircle of( TPoint point ) + { + self.point().set( point ); + return self; + } + + public TCircle of( double x, double y, double radius ) + { + yx( y, x ).radius( radius ); + return self; + } + + public TCircle yx( double y, double x ) + { + of( module.newValueBuilder( TPoint.class ).prototype().x( x ).y( y ) ); + return self; + } + + public TCircle yx( double y, double x, double radius ) + { + of( module.newValueBuilder( TPoint.class ).prototype().x( x ).y( y ) ).radius( radius ); + return self; + } + + public TCircle of( TPoint point, double r ) + { + of( point ).radius( r ); + return self; + } + + public TPoint getCentre() + { + return self.point().get(); + } + + public TCircle radius( double r ) + { + self.radius().set( r ); + return self; + } + + public TPolygon polygonize( int numOfPoints ) + { + double xRadius = self.radius().get(); + double yRadius = self.radius().get(); + + double centreX = self.getCentre().x(); + double centreY = self.getCentre().y(); + + TPoint[] pts = new TPoint[ numOfPoints + 1 ]; + int pt = 0; + for( int i = 0; i < numOfPoints; i++ ) + { + double ang = i * ( 2 * Math.PI / numOfPoints ); + double x = xRadius * Math.cos( ang ) + centreX; + double y = yRadius * Math.sin( ang ) + centreY; + pts[ pt++ ] = module.newValueBuilder( TPoint.class ).prototype().of().x( x ).y( y ); + } + + pts[ pt++ ] = module.newValueBuilder( TPoint.class ).prototype().of( pts[ 0 ].getCoordinates() ); + TLinearRing tLinearRing = (TLinearRing) module.newValueBuilder( TLinearRing.class ).prototype().of( pts ); + + if( tLinearRing.isValid() ) + { + TPolygon tPolygon = module.newValueBuilder( TPolygon.class ).prototype().of( tLinearRing ); + tPolygon.setCRS( self.getCRS() ); + return module.newValueBuilder( TPolygon.class ).prototype().of( tLinearRing ); + } + else + { + return null; + } + } + } +}
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 b47abec..67d7799 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
@@ -14,26 +14,21 @@ package org.qi4j.api.geometry; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.qi4j.api.common.Optional; -import org.qi4j.api.geometry.internal.Coordinate; -import org.qi4j.api.geometry.internal.TGeometry; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; import org.qi4j.api.property.Property; import org.qi4j.api.structure.Module; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - - -@Mixins(TFeature.Mixin.class) +@Mixins( TFeature.Mixin.class ) public interface TFeature extends TGeometry { - @Optional Property<Map<String, List<String>>> properties(); @@ -42,18 +37,16 @@ Property<TGeometry> geometry(); + TFeature of( TGeometry geometry ); - TFeature of(TGeometry geometry); + TFeature withProperties( Map<String, List<String>> properties ); - TFeature withProperties(Map<String, List<String>> properties); - - TFeature addProperty(String name, String value); + TFeature addProperty( String name, String value ); TGeometry asGeometry(); Map<String, List<String>> asProperties(); - public abstract class Mixin implements TFeature { @@ -63,41 +56,44 @@ @This TFeature self; - public TFeature of(TGeometry geometry) + public TFeature of( TGeometry geometry ) { - self.geometryType().set(TGEOMETRY_TYPE.FEATURE); - self.geometry().set(geometry); + self.geometryType().set( TGEOMETRY_TYPE.FEATURE ); + self.geometry().set( geometry ); return self; } - public TFeature withProperties(Map<String, List<String>> properties) + public TFeature withProperties( Map<String, List<String>> properties ) { - self.properties().set(properties); + self.properties().set( properties ); return self; } - public TFeature addProperty(String name, String value) + public TFeature addProperty( String name, String value ) { - if (self.properties() == null || self.properties().get() == null || !self.properties().get().containsKey(name)) + if( self.properties() == null || self.properties().get() == null || !self.properties() + .get() + .containsKey( name ) ) { Map<String, List<String>> properties = new HashMap<>(); - properties.put(name, Arrays.asList(value)); - self.properties().set(properties); - } else + properties.put( name, Arrays.asList( value ) ); + self.properties().set( properties ); + } + else { - self.properties().get().get(name).add(value); + self.properties().get().get( name ).add( value ); } return self; } - public boolean isEmpty() { - return (self.geometry() == null) || (self.geometry().get() == null) || (self.geometry().get().isEmpty()) ? true : false; + return ( self.geometry() == null ) || ( self.geometry().get() == null ) || ( self.geometry() + .get() + .isEmpty() ) ? true : false; } - public Coordinate[] getCoordinates() { return self.geometry().get().getCoordinates(); @@ -108,7 +104,6 @@ return isEmpty() ? 0 : self.geometry().get().getNumPoints(); } - public TGeometry asGeometry() { return self.geometry().get(); @@ -118,7 +113,5 @@ { return self.properties().get(); } - } - }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TFeatureCollection.java b/core/api/src/main/java/org/qi4j/api/geometry/TFeatureCollection.java index 99593d3..afe3e6c 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/TFeatureCollection.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TFeatureCollection.java
@@ -14,22 +14,20 @@ package org.qi4j.api.geometry; -import org.qi4j.api.geometry.internal.GeometryCollections; -import org.qi4j.api.geometry.internal.TGeometry; +import java.util.ArrayList; +import java.util.List; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; import org.qi4j.api.structure.Module; -import java.util.ArrayList; -import java.util.List; - -@Mixins(TFeatureCollection.Mixin.class) +@Mixins( TFeatureCollection.Mixin.class ) public interface TFeatureCollection extends GeometryCollections { - TFeatureCollection of(TFeature... features); - TFeatureCollection of(List<TFeature> features); + TFeatureCollection of( TFeature... features ); + + TFeatureCollection of( List<TFeature> features ); public abstract class Mixin extends GeometryCollections.Mixin implements TFeatureCollection { @@ -39,27 +37,31 @@ @This TFeatureCollection self; - public TFeatureCollection of(List<TFeature> features) + public TFeatureCollection of( List<TFeature> features ) { - of(features.toArray(new TFeature[features.size()])); + of( features.toArray( new TFeature[ features.size() ] ) ); return self; } - public TFeatureCollection of(TFeature... features) + public TFeatureCollection of( TFeature... features ) { - self.geometryType().set(TGEOMETRY_TYPE.FEATURECOLLECTION); + self.geometryType().set( TGEOMETRY_TYPE.FEATURECOLLECTION ); init(); List<TGeometry> l = new ArrayList<>(); - for (TFeature f : features) + for( TFeature f : features ) { - l.add(f); + l.add( f ); } - if (self.isEmpty()) - self.geometries().set(l); + if( self.isEmpty() ) + { + self.geometries().set( l ); + } else - self.geometries().get().addAll(l); + { + self.geometries().get().addAll( l ); + } return self; }
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/TGeometry.java similarity index 62% rename from core/api/src/main/java/org/qi4j/api/geometry/internal/TGeometry.java rename to core/api/src/main/java/org/qi4j/api/geometry/TGeometry.java index 533ee14..463fa93 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/TGeometry.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TGeometry.java
@@ -12,11 +12,10 @@ * */ -package org.qi4j.api.geometry.internal; +package org.qi4j.api.geometry; import org.qi4j.api.common.Optional; import org.qi4j.api.common.UseDefaults; -import org.qi4j.api.geometry.*; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; @@ -24,7 +23,7 @@ import org.qi4j.api.structure.Module; import org.qi4j.api.value.ValueComposite; -@Mixins(TGeometry.Mixin.class) +@Mixins( TGeometry.Mixin.class ) public interface TGeometry extends ValueComposite { enum TGEOMETRY_TYPE @@ -37,8 +36,10 @@ @Optional @UseDefaults Property<String> CRS(); + String getCRS(); - void setCRS(String crs); + + void setCRS( String crs ); abstract Coordinate[] getCoordinates(); @@ -49,33 +50,40 @@ TGEOMETRY_TYPE getType(); boolean isPoint(); - boolean isPoint(TGeometry tGeometry); + + boolean isPoint( TGeometry tGeometry ); boolean isMultiPoint(); - boolean isMultiPoint(TGeometry tGeometry); + + boolean isMultiPoint( TGeometry tGeometry ); boolean isLineString(); - boolean isLineString(TGeometry tGeometry); + + boolean isLineString( TGeometry tGeometry ); boolean isMultiLineString(); - boolean isMultiLineString(TGeometry tGeometry); + + boolean isMultiLineString( TGeometry tGeometry ); boolean isPolygon(); - boolean isPolygon(TGeometry tGeometry); + + boolean isPolygon( TGeometry tGeometry ); boolean isMultiPolygon(); - boolean isMultiPolygon(TGeometry tGeometry); + + boolean isMultiPolygon( TGeometry tGeometry ); boolean isFeature(); - boolean isFeature(TGeometry tGeometry); + + boolean isFeature( TGeometry tGeometry ); boolean isFeatureCollection(); - boolean isFeatureCollection(TGeometry tGeometry); + + boolean isFeatureCollection( TGeometry tGeometry ); boolean isGeometry(); - boolean isGeometry(Object tGeometry); - + boolean isGeometry( Object tGeometry ); public abstract class Mixin implements TGeometry { @@ -91,12 +99,11 @@ return self.CRS().get(); } - public void setCRS(String crs) + public void setCRS( String crs ) { - self.CRS().set(crs); + self.CRS().set( crs ); } - public int getNumPoints() { return 0; @@ -104,37 +111,37 @@ public Coordinate[] getCoordinates() { - throw new RuntimeException("Should never be called"); + throw new RuntimeException( "Should never be called" ); } public boolean isEmpty() { - throw new RuntimeException("Should never be called"); + throw new RuntimeException( "Should never be called" ); } public TGEOMETRY_TYPE getType() { // "strong typing" - type & instanceOf must match - switch (self.geometryType().get()) + switch( self.geometryType().get() ) { - case POINT: - return self.isPoint() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.POINT; - case MULTIPOINT: - return self.isMultiPoint() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.MULTIPOINT; - case LINESTRING: - return self.isLineString() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.LINESTRING; - case MULTILINESTRING: - return self.isMultiLineString() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.MULTILINESTRING; - case POLYGON: - return self.isPolygon() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.POLYGON; - case MULTIPOLYGON: - return self.isMultiPolygon() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.MULTIPOLYGON; - case FEATURE: - return self.isFeature() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.FEATURE; - case FEATURECOLLECTION: - return self.isFeatureCollection() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.FEATURECOLLECTION; - default: - return TGEOMETRY_TYPE.INVALID; + case POINT: + return self.isPoint() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.POINT; + case MULTIPOINT: + return self.isMultiPoint() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.MULTIPOINT; + case LINESTRING: + return self.isLineString() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.LINESTRING; + case MULTILINESTRING: + return self.isMultiLineString() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.MULTILINESTRING; + case POLYGON: + return self.isPolygon() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.POLYGON; + case MULTIPOLYGON: + return self.isMultiPolygon() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.MULTIPOLYGON; + case FEATURE: + return self.isFeature() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.FEATURE; + case FEATURECOLLECTION: + return self.isFeatureCollection() == false ? TGEOMETRY_TYPE.INVALID : TGEOMETRY_TYPE.FEATURECOLLECTION; + default: + return TGEOMETRY_TYPE.INVALID; } } @@ -142,7 +149,8 @@ { return self instanceof TPoint ? true : false; } - public boolean isPoint(TGeometry tGeometry) + + public boolean isPoint( TGeometry tGeometry ) { return tGeometry instanceof TPoint ? true : false; } @@ -151,7 +159,8 @@ { return self instanceof TMultiPoint ? true : false; } - public boolean isMultiPoint(TGeometry tGeometry) + + public boolean isMultiPoint( TGeometry tGeometry ) { return tGeometry instanceof TMultiPoint ? true : false; } @@ -160,7 +169,8 @@ { return self instanceof TLineString ? true : false; } - public boolean isLineString(TGeometry tGeometry) + + public boolean isLineString( TGeometry tGeometry ) { return tGeometry instanceof TLineString ? true : false; } @@ -169,7 +179,8 @@ { return self instanceof TMultiLineString ? true : false; } - public boolean isMultiLineString(TGeometry tGeometry) + + public boolean isMultiLineString( TGeometry tGeometry ) { return tGeometry instanceof TMultiLineString ? true : false; } @@ -178,7 +189,8 @@ { return self instanceof TPolygon ? true : false; } - public boolean isPolygon(TGeometry tGeometry) + + public boolean isPolygon( TGeometry tGeometry ) { return tGeometry instanceof TPolygon ? true : false; } @@ -187,7 +199,8 @@ { return self instanceof TMultiPolygon ? true : false; } - public boolean isMultiPolygon(TGeometry tGeometry) + + public boolean isMultiPolygon( TGeometry tGeometry ) { return tGeometry instanceof TMultiPolygon ? true : false; } @@ -196,7 +209,8 @@ { return self instanceof TFeature ? true : false; } - public boolean isFeature(TGeometry tGeometry) + + public boolean isFeature( TGeometry tGeometry ) { return tGeometry instanceof TFeature ? true : false; } @@ -205,7 +219,8 @@ { return self instanceof TFeatureCollection ? true : false; } - public boolean isFeatureCollection(TGeometry tGeometry) + + public boolean isFeatureCollection( TGeometry tGeometry ) { return tGeometry instanceof TFeatureCollection ? true : false; } @@ -214,10 +229,10 @@ { return self instanceof TGeometry ? true : false; } - public boolean isGeometry(Object tGeometry) + + public boolean isGeometry( Object tGeometry ) { return tGeometry instanceof TGeometry ? true : false; } } - }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TGeometryFactory.java b/core/api/src/main/java/org/qi4j/api/geometry/TGeometryFactory.java deleted file mode 100644 index 7292e28..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/TGeometryFactory.java +++ /dev/null
@@ -1,67 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry; - -import org.qi4j.api.geometry.internal.builders.*; -import org.qi4j.api.structure.Module; - - -public class TGeometryFactory -{ - - - public static TCRSBuilder TCrs(Module module) - { - return new TCRSBuilder(module); - } - public static TPointBuilder TPoint(Module module) - { - return new TPointBuilder(module); - } - - public static TMultiPointBuilder TMultiPoint(Module module) - { - return new TMultiPointBuilder(module); - } - public static TLinearRingBuilder TLinearRing(Module module) - { - return new TLinearRingBuilder(module); - } - public static TLineStringBuilder TLineString(Module module) - { - return new TLineStringBuilder(module); - } - public static TMultiLineStringBuilder TMultiLineString(Module module) - { - return new TMultiLineStringBuilder(module); - } - - public static TPolygonBuilder TPolygon(Module module) - { - return new TPolygonBuilder(module); - } - public static TMultiPolygonsBuilder TMultiPolygon(Module module) - { - return new TMultiPolygonsBuilder(module); - } - public static TFeatureBuilder TFeature(Module module) - { - return new TFeatureBuilder(module); - } - public static TFeatureCollectionBuilder TFeatureCollection(Module module) - { - return new TFeatureCollectionBuilder(module); - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TLineString.java b/core/api/src/main/java/org/qi4j/api/geometry/TLineString.java index d9b0959..b6e60e8 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/TLineString.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TLineString.java
@@ -14,42 +14,44 @@ package org.qi4j.api.geometry; -import org.qi4j.api.geometry.internal.Coordinate; -import org.qi4j.api.geometry.internal.TGeometry; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; import org.qi4j.api.property.Property; import org.qi4j.api.structure.Module; -import java.util.ArrayList; -import java.util.List; - - -@Mixins(TLineString.Mixin.class) +@Mixins( TLineString.Mixin.class ) public interface TLineString extends TGeometry { Property<List<TPoint>> points(); - TLineString of(TPoint... points); - TLineString of(List<TPoint> points); + TLineString of( TPoint... points ); + + TLineString of( List<TPoint> points ); + TLineString of(); - TLineString yx(double y, double x); + TLineString yx( double y, double x ); boolean isEmpty(); int getNumPoints(); - TPoint getPointN(int n); + TPoint getPointN( int n ); + TPoint getStartPoint(); + TPoint getEndPoint(); boolean isClosed(); + boolean isRing(); - int compareTo(TLineString line); + int compareTo( TLineString line ); public abstract class Mixin implements TLineString { @@ -59,26 +61,25 @@ @Structure Module module; - public TLineString of(List<TPoint> points) + public TLineString of( List<TPoint> points ) { - of(points.toArray(new TPoint[points.size()])); + of( points.toArray( new TPoint[ points.size() ] ) ); return self; } - - public TLineString of(TPoint... points) + public TLineString of( TPoint... points ) { - List<TPoint> l = new ArrayList<>(); - for (TPoint p : points) + Collections.addAll( l, points ); + if( self.isEmpty() ) { - l.add(p); + self.points().set( l ); } - if (self.isEmpty()) - self.points().set(l); else - self.points().get().addAll(l); - self.geometryType().set(TGEOMETRY_TYPE.LINESTRING); + { + self.points().get().addAll( l ); + } + self.geometryType().set( TGEOMETRY_TYPE.LINESTRING ); return self; } @@ -87,15 +88,17 @@ return self; } - public TLineString yx(double y, double x) + public TLineString yx( double y, double x ) { - of(module.newValueBuilder(TPoint.class).prototype().x(x).y(y)); + of( module.newValueBuilder( TPoint.class ).prototype().x( x ).y( y ) ); return self; } public boolean isEmpty() { - return (self.points() == null) || (self.points().get() == null) || (self.points().get().isEmpty()) ? true : false; + return ( self.points() == null ) || + ( self.points().get() == null ) || + ( self.points().get().isEmpty() ); } public int getNumPoints() @@ -103,40 +106,40 @@ return isEmpty() ? 0 : self.points().get().size(); } - public TPoint getPointN(int n) + public TPoint getPointN( int n ) { - return self.points().get().get(n); + return self.points().get().get( n ); } public TPoint getStartPoint() { - if (isEmpty()) + if( isEmpty() ) { return null; } - return getPointN(0); + return getPointN( 0 ); } public TPoint getEndPoint() { - if (isEmpty()) + if( isEmpty() ) { return null; } - return getPointN(getNumPoints() - 1); + return getPointN( getNumPoints() - 1 ); } public Coordinate[] getCoordinates() { int k = -1; - Coordinate[] coordinates = new Coordinate[getNumPoints()]; - for (int i = 0; i < getNumPoints(); i++) + Coordinate[] coordinates = new Coordinate[ getNumPoints() ]; + for( int i = 0; i < getNumPoints(); i++ ) { - Coordinate[] childCoordinates = getPointN(i).getCoordinates(); - for (int j = 0; j < childCoordinates.length; j++) + Coordinate[] childCoordinates = getPointN( i ).getCoordinates(); + for( Coordinate childCoordinate : childCoordinates ) { k++; - coordinates[k] = childCoordinates[j]; + coordinates[ k ] = childCoordinate; } } return coordinates; @@ -144,11 +147,11 @@ public boolean isClosed() { - if (isEmpty()) + if( isEmpty() ) { return false; } - return getStartPoint().compareTo(getEndPoint()) == 0 ? true : false; + return getStartPoint().compareTo( getEndPoint() ) == 0; } public boolean isRing() @@ -156,32 +159,30 @@ return isClosed(); } - public int compareTo(TLineString line) + public int compareTo( TLineString line ) { int i = 0; int j = 0; - while (i < self.getNumPoints() && j < line.getNumPoints()) + while( i < self.getNumPoints() && j < line.getNumPoints() ) { - int comparison = self.getPointN(i).compareTo(line.getPointN(j)); - if (comparison != 0) + int comparison = self.getPointN( i ).compareTo( line.getPointN( j ) ); + if( comparison != 0 ) { return comparison; } i++; j++; } - if (i < self.getNumPoints()) + if( i < self.getNumPoints() ) { return 1; } - if (j < line.getNumPoints()) + if( j < line.getNumPoints() ) { return -1; } return 0; } - } - }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/TLinearRing.java b/core/api/src/main/java/org/qi4j/api/geometry/TLinearRing.java similarity index 76% rename from core/api/src/main/java/org/qi4j/api/geometry/internal/TLinearRing.java rename to core/api/src/main/java/org/qi4j/api/geometry/TLinearRing.java index 2b99f9a..d669589 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/TLinearRing.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TLinearRing.java
@@ -12,13 +12,12 @@ * */ -package org.qi4j.api.geometry.internal; +package org.qi4j.api.geometry; -import org.qi4j.api.geometry.TLineString; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; -@Mixins(TLinearRing.Mixin.class) +@Mixins( TLinearRing.Mixin.class ) public interface TLinearRing extends TLineString { @@ -32,9 +31,11 @@ @Override public boolean isValid() { - if (self.getStartPoint() == null || self.getEndPoint() == null) return false; - return self.getStartPoint().compareTo(self.getEndPoint()) == 0 ? true : false; + if( self.getStartPoint() == null || self.getEndPoint() == null ) + { + return false; + } + return self.getStartPoint().compareTo( self.getEndPoint() ) == 0 ? true : false; } } - }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TMultiLineString.java b/core/api/src/main/java/org/qi4j/api/geometry/TMultiLineString.java index 3d8ba09..5c15785 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/TMultiLineString.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TMultiLineString.java
@@ -14,23 +14,20 @@ package org.qi4j.api.geometry; -import org.qi4j.api.geometry.internal.GeometryCollections; -import org.qi4j.api.geometry.internal.TGeometry; +import java.util.ArrayList; +import java.util.List; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; import org.qi4j.api.structure.Module; -import java.util.ArrayList; -import java.util.List; - -@Mixins(TMultiLineString.Mixin.class) +@Mixins( TMultiLineString.Mixin.class ) public interface TMultiLineString extends GeometryCollections { - TMultiLineString of(TLineString... lines); + TMultiLineString of( TLineString... lines ); - TMultiLineString of(List<TLineString> lines); + TMultiLineString of( List<TLineString> lines ); public abstract class Mixin extends GeometryCollections.Mixin implements TMultiLineString { @@ -40,26 +37,30 @@ @This TMultiLineString self; - public TMultiLineString of(List<TLineString> lines) + public TMultiLineString of( List<TLineString> lines ) { - of(lines.toArray(new TLineString[lines.size()])); + of( lines.toArray( new TLineString[ lines.size() ] ) ); return self; } - public TMultiLineString of(TLineString... lines) + public TMultiLineString of( TLineString... lines ) { - self.geometryType().set(TGEOMETRY_TYPE.MULTILINESTRING); + self.geometryType().set( TGEOMETRY_TYPE.MULTILINESTRING ); init(); List<TGeometry> l = new ArrayList<>(); - for (TLineString p : lines) + for( TLineString p : lines ) { - l.add(p); + l.add( p ); } - if (self.isEmpty()) - self.geometries().set(l); + if( self.isEmpty() ) + { + self.geometries().set( l ); + } else - self.geometries().get().addAll(l); + { + self.geometries().get().addAll( l ); + } return self; } }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TMultiPoint.java b/core/api/src/main/java/org/qi4j/api/geometry/TMultiPoint.java index 00e0a6f..7433034 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/TMultiPoint.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TMultiPoint.java
@@ -14,23 +14,21 @@ package org.qi4j.api.geometry; -import org.qi4j.api.geometry.internal.GeometryCollections; -import org.qi4j.api.geometry.internal.TGeometry; +import java.util.ArrayList; +import java.util.List; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; import org.qi4j.api.structure.Module; -import java.util.ArrayList; -import java.util.List; - - -@Mixins(TMultiPoint.Mixin.class) +@Mixins( TMultiPoint.Mixin.class ) public interface TMultiPoint extends GeometryCollections { - TMultiPoint of(TPoint... points); - TMultiPoint of(List<TPoint> points); - TMultiPoint yx(double y, double x); + TMultiPoint of( TPoint... points ); + + TMultiPoint of( List<TPoint> points ); + + TMultiPoint yx( double y, double x ); public abstract class Mixin extends GeometryCollections.Mixin implements TMultiPoint { @@ -39,29 +37,35 @@ @Structure Module module; - public TMultiPoint of(List<TPoint> points) + public TMultiPoint of( List<TPoint> points ) { - of(points.toArray(new TPoint[points.size()])); + of( points.toArray( new TPoint[ points.size() ] ) ); return self; } - public TMultiPoint yx(double y, double x) + + public TMultiPoint yx( double y, double x ) { - of(module.newValueBuilder(TPoint.class).prototype().x(x).y(y)); + of( module.newValueBuilder( TPoint.class ).prototype().x( x ).y( y ) ); return self; } - public TMultiPoint of(TPoint... points) + + public TMultiPoint of( TPoint... points ) { - self.geometryType().set(TGEOMETRY_TYPE.MULTIPOINT); + self.geometryType().set( TGEOMETRY_TYPE.MULTIPOINT ); init(); List<TGeometry> l = new ArrayList<>(); - for (TPoint p : points) + for( TPoint p : points ) { - l.add(p); + l.add( p ); } - if (self.isEmpty()) - self.geometries().set(l); // points().set(l); + if( self.isEmpty() ) + { + self.geometries().set( l ); // points().set(l); + } else - self.geometries().get().addAll(l); + { + self.geometries().get().addAll( l ); + } return self; }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TMultiPolygon.java b/core/api/src/main/java/org/qi4j/api/geometry/TMultiPolygon.java index 4eb37c1..ec487bb 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/TMultiPolygon.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TMultiPolygon.java
@@ -14,23 +14,20 @@ package org.qi4j.api.geometry; -import org.qi4j.api.geometry.internal.GeometryCollections; -import org.qi4j.api.geometry.internal.TGeometry; +import java.util.ArrayList; +import java.util.List; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; import org.qi4j.api.structure.Module; -import java.util.ArrayList; -import java.util.List; - -@Mixins(TMultiPolygon.Mixin.class) +@Mixins( TMultiPolygon.Mixin.class ) public interface TMultiPolygon extends GeometryCollections { - TMultiPolygon of(TPolygon... polygons); + TMultiPolygon of( TPolygon... polygons ); - TMultiPolygon of(List<TPolygon> polygons); + TMultiPolygon of( List<TPolygon> polygons ); public abstract class Mixin extends GeometryCollections.Mixin implements TMultiPolygon { @@ -40,28 +37,31 @@ @This TMultiPolygon self; - public TMultiPolygon of(List<TPolygon> polygons) + public TMultiPolygon of( List<TPolygon> polygons ) { - of(polygons.toArray(new TPolygon[polygons.size()])); + of( polygons.toArray( new TPolygon[ polygons.size() ] ) ); return self; } - public TMultiPolygon of(TPolygon... polygons) + public TMultiPolygon of( TPolygon... polygons ) { init(); - self.geometryType().set(TGEOMETRY_TYPE.MULTIPOLYGON); + self.geometryType().set( TGEOMETRY_TYPE.MULTIPOLYGON ); List<TGeometry> l = new ArrayList<>(); - for (TPolygon p : polygons) + for( TPolygon p : polygons ) { - l.add(p); + l.add( p ); } - if (self.isEmpty()) - self.geometries().set(l); + if( self.isEmpty() ) + { + self.geometries().set( l ); + } else - self.geometries().get().addAll(l); + { + self.geometries().get().addAll( l ); + } return self; } - } }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TPoint.java b/core/api/src/main/java/org/qi4j/api/geometry/TPoint.java index 268d78c..0ac2b06 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/TPoint.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TPoint.java
@@ -14,17 +14,15 @@ package org.qi4j.api.geometry; -import org.qi4j.api.geometry.internal.Coordinate; -import org.qi4j.api.geometry.internal.TGeometry; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; import org.qi4j.api.property.Property; import org.qi4j.api.structure.Module; -import java.util.ArrayList; -import java.util.List; - /** * Lat = Y Lon = X * @@ -34,23 +32,23 @@ * additional dimensions are allowed, and interpretation and meaning of these coordinates is beyond the scope of * this specification. */ -@Mixins(TPoint.Mixin.class) +@Mixins( TPoint.Mixin.class ) public interface TPoint extends TGeometry { Property<List<Coordinate>> coordinates(); - TPoint of(Coordinate... coordinates); + TPoint of( Coordinate... coordinates ); - TPoint of(double x, double y, double z); + TPoint of( double x, double y, double z ); TPoint of(); - TPoint x(double x); + TPoint x( double x ); - TPoint y(double y); + TPoint y( double y ); - TPoint z(double z); + TPoint z( double z ); double x(); @@ -60,102 +58,108 @@ Coordinate getCoordinate(); - int compareTo(Object o); - + int compareTo( Object o ); public abstract class Mixin implements TPoint { @Structure - Module module; + private Module module; + @This - TPoint self; + private TPoint self; private void init() { - if (self.coordinates().get() == null) + if( self.coordinates().get() == null ) { - List<Coordinate> c = new ArrayList<Coordinate>(); - c.add(module.newValueBuilder(Coordinate.class).prototype().x(0).y(0).z(0)); - self.coordinates().set(c); - self.geometryType().set(TGEOMETRY_TYPE.POINT); + c.add( module.newValueBuilder( Coordinate.class ).prototype().x( 0 ).y( 0 ).z( 0 ) ); + self.coordinates().set( c ); + self.geometryType().set( TGEOMETRY_TYPE.POINT ); } } @Override public boolean isEmpty() { - return (self.coordinates() == null) || (self.coordinates().get() == null) || (self.coordinates().get().isEmpty()) ? true : false; + return ( self.coordinates() == null ) || + ( self.coordinates().get() == null ) || + ( self.coordinates().get().isEmpty() ); } - public TPoint of() { - if (isEmpty()) - return self.of(0.0d, 0.0d, 0.0d); + if( isEmpty() ) + { + return self.of( 0.0d, 0.0d, 0.0d ); + } else + { return self; + } } - public TPoint of(double x, double y, double z) + + public TPoint of( double x, double y, double z ) { init(); - self.x(x).y(y).z(z); - self.geometryType().set(TGEOMETRY_TYPE.POINT); + self.x( x ).y( y ).z( z ); + self.geometryType().set( TGEOMETRY_TYPE.POINT ); return self; } - public TPoint of(Coordinate... coordinates) + public TPoint of( Coordinate... coordinates ) { List<Coordinate> c = new ArrayList<Coordinate>(); - - for (Coordinate xyzn : coordinates) - { - c.add(xyzn); - } - self.coordinates().set(c); - self.geometryType().set(TGEOMETRY_TYPE.POINT); + Collections.addAll( c, coordinates ); + self.coordinates().set( c ); + self.geometryType().set( TGEOMETRY_TYPE.POINT ); return self; } - public TPoint x(double x) + public TPoint x( double x ) { init(); - self.coordinates().get().get(0).x(x); + self.coordinates().get().get( 0 ).x( x ); return self; } public double x() { - return self.coordinates().get().get(0).getOrdinate(Coordinate.X); + return self.coordinates().get().get( 0 ).getOrdinate( Coordinate.X ); } - public TPoint y(double y) + + public TPoint y( double y ) { init(); - self.coordinates().get().get(0).y(y); - return self; - } - public double y() - { - return self.coordinates().get().get(0).getOrdinate(Coordinate.Y); - } - public double z() - { - return self.coordinates().get().get(0).getOrdinate(Coordinate.Z); - } - public TPoint z(double z) - { - init(); - self.coordinates().get().get(0).z(z); + self.coordinates().get().get( 0 ).y( y ); return self; } - public TPoint of(List<Double> coordinates) + public double y() { + return self.coordinates().get().get( 0 ).getOrdinate( Coordinate.Y ); + } + + public double z() + { + return self.coordinates().get().get( 0 ).getOrdinate( Coordinate.Z ); + } + + public TPoint z( double z ) + { + init(); + self.coordinates().get().get( 0 ).z( z ); + return self; + } + + public TPoint of( List<Double> coordinates ) + { + // TODO; [niclas] Must be something wrong here... List<Coordinate> c = new ArrayList<Coordinate>(); - for (Double xyzn : coordinates) + for( Double xyzn : coordinates ) { - c.add(module.newValueBuilder(Coordinate.class).prototype().of(xyzn)); + c.add( module.newValueBuilder( Coordinate.class ).prototype().of( xyzn ) ); } return null; } @@ -164,13 +168,13 @@ public Coordinate[] getCoordinates() { List<Coordinate> coordinates = new ArrayList<>(); - coordinates.add(getCoordinate()); - return coordinates.toArray(new Coordinate[coordinates.size()]); + coordinates.add( getCoordinate() ); + return coordinates.toArray( new Coordinate[ coordinates.size() ] ); } public Coordinate getCoordinate() { - return self.coordinates().get().size() != 0 ? self.coordinates().get().get(0) : null; + return self.coordinates().get().size() != 0 ? self.coordinates().get().get( 0 ) : null; } public int getNumPoints() @@ -178,12 +182,10 @@ return isEmpty() ? 0 : 1; } - public int compareTo(Object other) + public int compareTo( Object other ) { TPoint point = (TPoint) other; - return getCoordinate().compareTo(point.getCoordinate()); + return getCoordinate().compareTo( point.getCoordinate() ); } - } - }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TPolygon.java b/core/api/src/main/java/org/qi4j/api/geometry/TPolygon.java index 7c2b627..bee5e65 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/TPolygon.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TPolygon.java
@@ -14,22 +14,17 @@ package org.qi4j.api.geometry; +import java.util.ArrayList; +import java.util.List; 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.geometry.internal.TShape; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; import org.qi4j.api.property.Property; import org.qi4j.api.structure.Module; -import java.util.ArrayList; -import java.util.List; - -@Mixins(TPolygon.Mixin.class) -public interface TPolygon extends TShape, TGeometry +@Mixins( TPolygon.Mixin.class ) +public interface TPolygon extends TShape { Property<TLinearRing> shell(); @@ -37,58 +32,68 @@ @Optional Property<List<TLinearRing>> holes(); - TPolygon of(TLinearRing shell); - TPolygon of(TLinearRing shell, @Optional TLinearRing... holes); - TPolygon withHole(TLinearRing hole); - TPolygon withHoles(@Optional TLinearRing... holes); + TPolygon of( TLinearRing shell ); + + TPolygon of( TLinearRing shell, @Optional TLinearRing... holes ); + + TPolygon withHole( TLinearRing hole ); + + TPolygon withHoles( @Optional TLinearRing... holes ); + boolean isEmpty(); public abstract class Mixin implements TPolygon { @Structure - Module module; + private Module module; @This - TPolygon self; + private TPolygon self; private void init() { - if (self.holes().get() == null) + if( self.holes().get() == null ) { List<TLinearRing> ring = new ArrayList<>(); - self.holes().set(ring); - self.geometryType().set(TGEOMETRY_TYPE.POINT); + self.holes().set( ring ); + self.geometryType().set( TGEOMETRY_TYPE.POINT ); } } - public TPolygon of(TLinearRing shell) + public TPolygon of( TLinearRing shell ) { - return of(shell, null); + return of( shell, null ); } - public TPolygon of(TLinearRing shell, TLinearRing... holes) + public TPolygon of( TLinearRing shell, TLinearRing... holes ) { init(); - if (shell != null) + if( shell != null ) { - self.shell().set(shell); + self.shell().set( shell ); } - withHoles(holes); - self.geometryType().set(TGEOMETRY_TYPE.POLYGON); + withHoles( holes ); + self.geometryType().set( TGEOMETRY_TYPE.POLYGON ); return self; } - public TPolygon withHole(TLinearRing hole) + public TPolygon withHole( TLinearRing hole ) { - if (hole != null) self.holes().get().add(hole); + if( hole != null ) + { + self.holes().get().add( hole ); + } return self; } - public TPolygon withHoles(TLinearRing... holes) + + public TPolygon withHoles( TLinearRing... holes ) { - if (holes != null && holes.length != 0) + if( holes != null && holes.length != 0 ) { - for (TLinearRing hole : holes) - withHole(hole); + for( TLinearRing hole : holes ) + { + withHole( hole ); + } } return self; } @@ -96,25 +101,23 @@ @Override public Coordinate[] getCoordinates() { - if (isEmpty()) + if( isEmpty() ) { return new Coordinate[]{}; } - Coordinate[] coordinates = new Coordinate[getNumPoints()]; - int k = -1; + Coordinate[] coordinates = new Coordinate[ getNumPoints() ]; Coordinate[] shellCoordinates = self.shell().get().getCoordinates(); - for (int x = 0; x < shellCoordinates.length; x++) + int k = 0; + for( Coordinate shellCoordinate : shellCoordinates ) { - k++; - coordinates[k] = shellCoordinates[x]; + coordinates[ k++ ] = shellCoordinate; } - for (int i = 0; i < self.holes().get().size(); i++) + for( int i = 0; i < self.holes().get().size(); i++ ) { - Coordinate[] childCoordinates = self.holes().get().get(i).getCoordinates(); - for (int j = 0; j < childCoordinates.length; j++) + Coordinate[] childCoordinates = self.holes().get().get( i ).getCoordinates(); + for( Coordinate childCoordinate : childCoordinates ) { - k++; - coordinates[k] = childCoordinates[j]; + coordinates[ k++ ] = childCoordinate; } } return coordinates; @@ -122,16 +125,18 @@ public boolean isEmpty() { - return (self.shell() == null) || (self.shell().get() == null) || (self.shell().get().isEmpty()) ? true : false; + return ( self.shell() == null ) || + ( self.shell().get() == null ) || + ( self.shell().get().isEmpty() ); } public int getNumPoints() { int numPoints = self.shell().get().getNumPoints(); - for (int i = 0; i < self.holes().get().size(); i++) + for( int i = 0; i < self.holes().get().size(); i++ ) { - numPoints += self.holes().get().get(i).getNumPoints(); + numPoints += self.holes().get().get( i ).getNumPoints(); } return numPoints; }
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/TShape.java b/core/api/src/main/java/org/qi4j/api/geometry/TShape.java similarity index 94% rename from core/api/src/main/java/org/qi4j/api/geometry/internal/TShape.java rename to core/api/src/main/java/org/qi4j/api/geometry/TShape.java index d56eb71..70de84b 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/TShape.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TShape.java
@@ -12,7 +12,7 @@ * */ -package org.qi4j.api.geometry.internal; +package org.qi4j.api.geometry; public interface TShape extends TGeometry {
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TUnit.java b/core/api/src/main/java/org/qi4j/api/geometry/TUnit.java index 308fd9b..0099189 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/TUnit.java +++ b/core/api/src/main/java/org/qi4j/api/geometry/TUnit.java
@@ -32,6 +32,5 @@ USFOOT, YARD, UNIT, - SECOND, - + SECOND }
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 deleted file mode 100644 index e49e96e..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/Coordinate.java +++ /dev/null
@@ -1,189 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry.internal; - -import org.qi4j.api.common.Optional; -import org.qi4j.api.injection.scope.This; -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.property.Property; -import org.qi4j.api.value.ValueComposite; - -import java.util.ArrayList; -import java.util.List; - -/** - * Represents one single n-Dimensional coordinate in the n-Dimensional "space" - */ - -@Mixins(Coordinate.Mixin.class) -public interface Coordinate extends Comparable, ValueComposite -{ - - public static final int X = 0; - public static final int Y = 1; - public static final int Z = 2; - - // single coordinate store - @Optional - 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); - int compareTo(Object o); - double[] source(); - - public abstract class Mixin implements Coordinate - { - - List<Double> EMPTY = new ArrayList<>(X + Y + Z); - @This - Coordinate self; - - private void init() - { - if (isEmpty()) - { - EMPTY.add(new Double(0.0)); - EMPTY.add(new Double(0.0)); - EMPTY.add(new Double(0.0)); - - self.coordinate().set(EMPTY); - } - } - - private boolean isEmpty() - { - return (self.coordinate() == null) || (self.coordinate().get() == null) || (self.coordinate().get().isEmpty()) ? true : false; - } - - public Coordinate of() - { - return self.of(0.0d, 0.0d, 0.0d); - } - - public Coordinate of(double x, double y, double z) - { - init(); - self.x(x); - self.y(y); - self.z(z); - return self; - } - - - public double x() - { - return getOrdinate(X); - } - public double y() - { - return getOrdinate(Y); - } - public double z() - { - return getOrdinate(Z); - } - - public Coordinate x(double x) - { - init(); - if (!Double.isNaN(x) && !Double.isInfinite(x)) - { - self.coordinate().get().set(X, x); - } - return self; - } - - public Coordinate y(double y) - { - init(); - if (!Double.isNaN(y) && !Double.isInfinite(y)) - { - self.coordinate().get().set(Y, y); - } - return self; - } - - public Coordinate z(double z) - { - init(); - if (!Double.isNaN(z) && !Double.isInfinite(z)) - { - self.coordinate().get().set(Z, z); - } - return self; - } - - public int compareTo(Object o) - { - Coordinate other = (Coordinate) o; - if (self.coordinate().get().get(X) < other.coordinate().get().get(X)) return -1; - if (self.coordinate().get().get(X) > other.coordinate().get().get(X)) return 1; - if (self.coordinate().get().get(Y) < other.coordinate().get().get(Y)) return -1; - if (self.coordinate().get().get(Y) > other.coordinate().get().get(Y)) return 1; - return 0; - } - - public double getOrdinate(int ordinateIndex) - { - switch (ordinateIndex) - { - case X: - return self.coordinate().get().get(X); - case Y: - return self.coordinate().get().get(Y); - case Z: - return self.coordinate().get().get(Z); - } - throw new IllegalArgumentException("Invalid ordinate index: " + ordinateIndex); - } - - public double[] source() - { - double[] source = new double[X + Y + Z]; - source[X] = getOrdinate(X); - source[Y] = getOrdinate(Y); - source[Z] = getOrdinate(Z); - return source; - } - - - public Coordinate of(double... coordinates) - { - List<Double> l = new ArrayList<Double>(coordinates.length); - for (double xyzn : coordinates) - { - // only values that makes "sense" - if (!Double.isNaN(xyzn) && !Double.isInfinite(xyzn)) - l.add(new Double(xyzn)); - } - self.coordinate().set(l); - return self; - } - - - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/TCircle.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/TCircle.java deleted file mode 100644 index b52b28d..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/TCircle.java +++ /dev/null
@@ -1,116 +0,0 @@ -package org.qi4j.api.geometry.internal; - - -import org.qi4j.api.geometry.TPoint; -import org.qi4j.api.geometry.TPolygon; -import org.qi4j.api.injection.scope.Structure; -import org.qi4j.api.injection.scope.This; -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.property.Property; -import org.qi4j.api.structure.Module; - -@Mixins(TCircle.Mixin.class) -public interface TCircle extends TGeometry -{ - Property<TPoint> point(); - - Property<Double> radius(); - - TCircle of(TPoint point, double radius); - TCircle of(double x, double y, double radius); - TCircle of(TPoint point); - TCircle of(); - - TCircle yx(double y, double x); - TCircle yx(double y, double x, double radius); - - TCircle radius(double r); - TPoint getCentre(); - TPolygon polygonize(int numOfPoints); - - public abstract class Mixin implements TCircle - { - @This - TCircle self; - - @Structure - Module module; - - public TCircle of() - { - return self; - } - - public TCircle of(TPoint point) - { - self.point().set(point); - return self; - } - - public TCircle of(double x, double y, double radius) - { - yx(y, x).radius(radius); - return self; - } - - public TCircle yx(double y, double x) - { - of(module.newValueBuilder(TPoint.class).prototype().x(x).y(y)); - return self; - } - - public TCircle yx(double y, double x, double radius) - { - of(module.newValueBuilder(TPoint.class).prototype().x(x).y(y)).radius(radius); - return self; - } - - public TCircle of(TPoint point, double r) - { - of(point).radius(r); - return self; - } - - public TPoint getCentre() - { - return self.point().get(); - } - - public TCircle radius(double r) - { - self.radius().set(r); - return self; - } - - - public TPolygon polygonize(int numOfPoints) - { - double xRadius = self.radius().get(); - double yRadius = self.radius().get(); - - double centreX = self.getCentre().x(); - double centreY = self.getCentre().y(); - - TPoint[] pts = new TPoint[numOfPoints + 1]; - int pt = 0; - for (int i = 0; i < numOfPoints; i++) - { - double ang = i * (2 * Math.PI / numOfPoints); - double x = xRadius * Math.cos(ang) + centreX; - double y = yRadius * Math.sin(ang) + centreY; - pts[pt++] = module.newValueBuilder(TPoint.class).prototype().of().x(x).y(y); - } - - pts[pt++] = module.newValueBuilder(TPoint.class).prototype().of(pts[0].getCoordinates()); - TLinearRing tLinearRing = (TLinearRing) module.newValueBuilder(TLinearRing.class).prototype().of(pts); - - if (tLinearRing.isValid()) - { - TPolygon tPolygon = module.newValueBuilder(TPolygon.class).prototype().of(tLinearRing); - tPolygon.setCRS(self.getCRS()); - return module.newValueBuilder(TPolygon.class).prototype().of(tLinearRing); - } else - return null; - } - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TFeatureBuilder.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TFeatureBuilder.java deleted file mode 100644 index 7cce0bd..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TFeatureBuilder.java +++ /dev/null
@@ -1,57 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry.internal.builders; - -import org.qi4j.api.geometry.TFeature; -import org.qi4j.api.geometry.internal.TGeometry; -import org.qi4j.api.structure.Module; - - -public class TFeatureBuilder -{ - - private Module module; - private TFeature geometry; - - - public TFeatureBuilder(Module module) - { - this.module = module; - geometry = module.newValueBuilder(TFeature.class).prototype(); - } - - - public TFeatureBuilder of(TGeometry feature) - { - geometry.of(feature); - return this; - } - - public TFeatureBuilder addProperty(String name, String value) - { - geometry.addProperty(name, value); - return this; - } - - public TFeature geometry() - { - return geometry; - } - - public TFeature geometry(int srid) - { - return geometry(); - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TFeatureCollectionBuilder.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TFeatureCollectionBuilder.java deleted file mode 100644 index fd27562..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TFeatureCollectionBuilder.java +++ /dev/null
@@ -1,57 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry.internal.builders; - -import org.qi4j.api.geometry.TFeature; -import org.qi4j.api.geometry.TFeatureCollection; -import org.qi4j.api.structure.Module; - -import java.util.List; - -public class TFeatureCollectionBuilder -{ - - private Module module; - private TFeatureCollection geometry; - - - public TFeatureCollectionBuilder(Module module) - { - this.module = module; - geometry = module.newValueBuilder(TFeatureCollection.class).prototype(); - } - - public TFeatureCollectionBuilder of(List<TFeature> features) - { - geometry.of(features); - return this; - } - - public TFeatureCollectionBuilder of(TFeature... features) - { - geometry.of(features); - return this; - } - - public TFeatureCollection geometry() - { - return geometry; - } - - public TFeatureCollection geometry(int srid) - { - return geometry(); - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TLineStringBuilder.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TLineStringBuilder.java deleted file mode 100644 index 21b6f6d..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TLineStringBuilder.java +++ /dev/null
@@ -1,68 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry.internal.builders; - -import org.qi4j.api.geometry.TLineString; -import org.qi4j.api.geometry.TPoint; -import org.qi4j.api.structure.Module; - - -public class TLineStringBuilder -{ - - private Module module; - private TLineString geometry; - - - public TLineStringBuilder(Module module) - { - this.module = module; - geometry = module.newValueBuilder(TLineString.class).prototype(); - } - - - public TLineStringBuilder points(double[][] points) - { - for (double yx[] : points) - { - if (yx.length < 2) return null; - geometry.yx(yx[0], yx[1]); - } - return this; - } - - public TLineStringBuilder of(TPoint... points) - { - geometry().of(points); - return this; - } - - public TLineStringBuilder of() - { - geometry().of(); - return this; - } - - - public TLineString geometry() - { - return geometry; - } - - public TLineString geometry(int srid) - { - return geometry(); - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TLinearRingBuilder.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TLinearRingBuilder.java deleted file mode 100644 index b057cbb..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TLinearRingBuilder.java +++ /dev/null
@@ -1,62 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry.internal.builders; - -import org.qi4j.api.geometry.TPoint; -import org.qi4j.api.geometry.internal.TLinearRing; -import org.qi4j.api.structure.Module; - - -public class TLinearRingBuilder -{ - - private Module module; - private TLinearRing geometry; - - - public TLinearRingBuilder(Module module) - { - this.module = module; - geometry = module.newValueBuilder(TLinearRing.class).prototype(); - } - - - public TLinearRingBuilder ring(double[][] ring) - { - for (double xy[] : ring) - { - if (xy.length < 2) return null; - geometry.yx(xy[0], xy[1]); - } - return this; - } - - public TLinearRingBuilder of(TPoint... points) - { - geometry().of(points); - return this; - } - - public TLinearRing geometry() - { - - return geometry; - } - - public TLinearRing geometry(int srid) - { - return geometry(); - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TMultiLineStringBuilder.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TMultiLineStringBuilder.java deleted file mode 100644 index c852d3a..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TMultiLineStringBuilder.java +++ /dev/null
@@ -1,68 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry.internal.builders; - -import org.qi4j.api.geometry.TLineString; -import org.qi4j.api.geometry.TMultiLineString; -import org.qi4j.api.structure.Module; - -import java.util.List; - -public class TMultiLineStringBuilder -{ - - private Module module; - private TMultiLineString geometry; - - - public TMultiLineStringBuilder(Module module) - { - this.module = module; - geometry = module.newValueBuilder(TMultiLineString.class).prototype(); - } - - - public TMultiLineStringBuilder points(double[][][] points) - { - for (double xy[][] : points) - { - if (xy.length < 2) return null; - } - return this; - } - - public TMultiLineStringBuilder of(List<TLineString> lines) - { - geometry.of(lines); - return this; - } - - public TMultiLineStringBuilder of(TLineString... lines) - { - geometry.of(lines); - return this; - } - - - public TMultiLineString geometry() - { - return geometry; - } - - public TMultiLineString geometry(int srid) - { - return geometry(); - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TMultiPointBuilder.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TMultiPointBuilder.java deleted file mode 100644 index 0fe8ad1..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TMultiPointBuilder.java +++ /dev/null
@@ -1,64 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry.internal.builders; - -import org.qi4j.api.geometry.TMultiPoint; -import org.qi4j.api.geometry.TPoint; -import org.qi4j.api.structure.Module; - -/** - * Created by jj on 26.11.14. - */ -public class TMultiPointBuilder -{ - - private Module module; - private TMultiPoint geometry; - - - public TMultiPointBuilder(Module module) - { - this.module = module; - geometry = module.newValueBuilder(TMultiPoint.class).prototype(); - } - - // Format { lat, lon } - public TMultiPointBuilder points(double[][] points) - { - for (double yx[] : points) - { - if (yx.length < 2) return null; - geometry.yx(yx[0], yx[1]); - } - return this; - } - - public TMultiPointBuilder of(TPoint... points) - { - geometry().of(points); - return this; - } - - public TMultiPoint geometry() - { - return geometry; - } - - public TMultiPoint geometry(String CRS) - { - geometry().setCRS(CRS); - return geometry(); - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TMultiPolygonsBuilder.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TMultiPolygonsBuilder.java deleted file mode 100644 index c57bb16..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TMultiPolygonsBuilder.java +++ /dev/null
@@ -1,69 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry.internal.builders; - -import org.qi4j.api.geometry.TMultiPolygon; -import org.qi4j.api.geometry.TPolygon; -import org.qi4j.api.structure.Module; - -import java.util.List; - - -public class TMultiPolygonsBuilder -{ - - private Module module; - private TMultiPolygon geometry; - - - public TMultiPolygonsBuilder(Module module) - { - this.module = module; - geometry = module.newValueBuilder(TMultiPolygon.class).prototype(); - } - - - public TMultiPolygonsBuilder points(double[][][] points) - { - for (double xy[][] : points) - { - if (xy.length < 2) return null; - } - return this; - } - - public TMultiPolygonsBuilder of(List<TPolygon> polygons) - { - geometry.of(polygons); - return this; - } - - public TMultiPolygonsBuilder of(TPolygon... polygons) - { - geometry.of(polygons); - return this; - } - - - public TMultiPolygon geometry() - { - return geometry; - } - - public TMultiPolygon geometry(int srid) - { - return geometry(); - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TPointBuilder.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TPointBuilder.java deleted file mode 100644 index d632459..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TPointBuilder.java +++ /dev/null
@@ -1,88 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry.internal.builders; - -import org.qi4j.api.geometry.TPoint; -import org.qi4j.api.geometry.internal.TGeometry; -import org.qi4j.api.structure.Module; - - -public class TPointBuilder -{ - - private Module module; - private TPoint geometry; - - - public TPointBuilder(Module module) - { - this.module = module; - geometry = module.newValueBuilder(TPoint.class).prototype(); - } - - public TPointBuilder x(double x) - { - geometry.x(x); - return this; - } - - public TPointBuilder y(double y) - { - geometry.y(y); - return this; - } - - public TPointBuilder z(double u) - { - geometry.z(u); - return this; - } - - - public TPointBuilder lat(double lat) - { - geometry.y(lat); - return this; - } - - public TPointBuilder lon(double lon) - { - geometry.x(lon); - return this; - } - - public TPointBuilder alt(double alt) - { - geometry.z(alt); - return this; - } - - - public boolean isPoint(TGeometry tGeometry) - { - return tGeometry instanceof TPoint ? true : false; - } - - public TPoint geometry() - { - return geometry; - } - - public TPoint geometry(String CRS) - { - geometry().setCRS(CRS); - return geometry(); - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TPolygonBuilder.java b/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TPolygonBuilder.java deleted file mode 100644 index d3f6b72..0000000 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TPolygonBuilder.java +++ /dev/null
@@ -1,64 +0,0 @@ -/* - * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. - * - * 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.api.geometry.internal.builders; - -import org.qi4j.api.geometry.TPolygon; -import org.qi4j.api.geometry.internal.TLinearRing; -import org.qi4j.api.structure.Module; - - -public class TPolygonBuilder -{ - - private Module module; - private TPolygon geometry; - - - public TPolygonBuilder(Module module) - { - this.module = module; - geometry = module.newValueBuilder(TPolygon.class).prototype(); - } - - public TPolygonBuilder shell(TLinearRing shell) - { - geometry.of(shell); - return this; - } - - public TPolygonBuilder shell(double[][] shell) - { - geometry.of(new TLinearRingBuilder(module).ring(shell).geometry()); - return this; - } - - public TPolygonBuilder withHoles(TLinearRing... holes) - { - geometry.withHoles(holes); - return this; - } - - - public TPolygon geometry() - { - return geometry; - } - - public TPolygon geometry(String CRS) - { - geometry().setCRS(CRS); - return geometry(); - } -}
diff --git a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/SpatialQueryExpressions.java b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/SpatialQueryExpressions.java index e1bdb34..48b673f 100644 --- a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/SpatialQueryExpressions.java +++ b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/SpatialQueryExpressions.java
@@ -2,8 +2,8 @@ import org.qi4j.api.geometry.TPoint; import org.qi4j.api.geometry.TUnit; -import org.qi4j.api.geometry.internal.TGeometry; -import org.qi4j.api.geometry.internal.TShape; +import org.qi4j.api.geometry.TGeometry; +import org.qi4j.api.geometry.TShape; import org.qi4j.api.property.Property; import org.qi4j.api.query.QueryExpressions; import org.qi4j.api.query.grammar.extensions.spatial.convert.ST_GeomFromTextSpecification; @@ -13,74 +13,100 @@ import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_WithinSpecification; import org.qi4j.functional.Specification; - public final class SpatialQueryExpressions extends QueryExpressions { // ST_Within - public static <T extends TGeometry> ST_WithinSpecification<TGeometry> ST_Within(Property<T> geometry, TPoint param, double distance, TUnit unit) + public static <T extends TGeometry> ST_WithinSpecification<T> ST_Within( Property<T> geometry, + TPoint param, + double distance, + TUnit unit + ) { - return new ST_WithinSpecification(property(geometry), param, distance, unit); + return new ST_WithinSpecification<>( property( geometry ), param, distance, unit ); } - public static <T extends TGeometry> ST_WithinSpecification<TGeometry> ST_Within(Property<T> geometry, TShape param) + public static <T extends TGeometry> ST_WithinSpecification<T> ST_Within( Property<T> geometry, + TShape param + ) { - return new ST_WithinSpecification(property(geometry), param); + return new ST_WithinSpecification<>( property( geometry ), param ); } - public static <T extends TGeometry> ST_WithinSpecification<TGeometry> ST_Within(Property<T> geometry, Specification<SpatialConvertSpecification> operator, double distance, TUnit unit) + public static <T extends TGeometry> ST_WithinSpecification<T> ST_Within( Property<T> geometry, + Specification<SpatialConvertSpecification> operator, + double distance, + TUnit unit + ) { - return new ST_WithinSpecification(property(geometry), operator, distance, unit); + return new ST_WithinSpecification<>( property( geometry ), operator, distance, unit ); } - public static <T extends TGeometry> ST_WithinSpecification<TGeometry> ST_Within(Property<T> geometry, Specification<SpatialConvertSpecification> operator) + public static <T extends TGeometry> ST_WithinSpecification<T> ST_Within( Property<T> geometry, + Specification<SpatialConvertSpecification> operator + ) { - return new ST_WithinSpecification(property(geometry), operator); + return new ST_WithinSpecification<>( property( geometry ), operator ); } // ST_Disjoint - public static <T extends TGeometry> ST_DisjointSpecification<TGeometry> ST_Disjoint(Property<T> geometry, Specification<SpatialConvertSpecification> operator, long distance) + public static <T extends TGeometry> ST_DisjointSpecification<T> ST_Disjoint( Property<T> geometry, + Specification<SpatialConvertSpecification> operator, + long distance + ) { - return new ST_DisjointSpecification(property(geometry), operator, distance); + return new ST_DisjointSpecification<>( property( geometry ), operator, distance ); } - public static <T extends TGeometry> ST_DisjointSpecification<TGeometry> ST_Disjoint(Property<T> geometry, TPoint param, double distance, TUnit unit) + public static <T extends TGeometry> ST_DisjointSpecification<T> ST_Disjoint( Property<T> geometry, + TPoint param, + double distance, + TUnit unit + ) { - return new ST_DisjointSpecification(property(geometry), param, distance, unit); + return new ST_DisjointSpecification<>( property( geometry ), param, distance, unit ); } - public static <T extends TGeometry> ST_DisjointSpecification<TGeometry> ST_Disjoint(Property<T> geometry, TShape param) + public static <T extends TGeometry> ST_DisjointSpecification<T> ST_Disjoint( Property<T> geometry, + TShape param + ) { - return new ST_DisjointSpecification(property(geometry), param); + return new ST_DisjointSpecification<>( property( geometry ), param ); } - // ST_Intersects - public static <T extends TGeometry> ST_IntersectsSpecification<TGeometry> ST_Intersects(Property<T> geometry, Specification<SpatialConvertSpecification> operator, long distance) + public static <T extends TGeometry> ST_IntersectsSpecification<T> ST_Intersects( Property<T> geometry, + Specification<SpatialConvertSpecification> operator, + long distance + ) { - return new ST_IntersectsSpecification(property(geometry), operator, distance); + return new ST_IntersectsSpecification<>( property( geometry ), operator, distance ); } - public static <T extends TGeometry> ST_IntersectsSpecification<TGeometry> ST_Intersects(Property<T> geometry, TPoint value, double distance, TUnit unit) + public static <T extends TGeometry> ST_IntersectsSpecification<T> ST_Intersects( Property<T> geometry, + TPoint value, + double distance, + TUnit unit + ) { - return new ST_IntersectsSpecification(property(geometry), value, distance, unit); + return new ST_IntersectsSpecification<>( property( geometry ), value, distance, unit ); } - public static <T extends TGeometry> ST_IntersectsSpecification<TGeometry> ST_Intersects(Property<T> geometry, TShape param) + public static <T extends TGeometry> ST_IntersectsSpecification<T> ST_Intersects( Property<T> geometry, + TShape param + ) { - return new ST_IntersectsSpecification(property(geometry), param); + return new ST_IntersectsSpecification<>( property( geometry ), param ); } - // ST_GeometryFromText - public static Specification<SpatialConvertSpecification> ST_GeometryFromText(String WKT) + public static Specification<SpatialConvertSpecification> ST_GeometryFromText( String WKT ) { - return ST_GeometryFromText(WKT, null); + return ST_GeometryFromText( WKT, null ); } - public static Specification<SpatialConvertSpecification> ST_GeometryFromText(String WKT, String crs) + public static Specification<SpatialConvertSpecification> ST_GeometryFromText( String WKT, String crs ) { - return new ST_GeomFromTextSpecification(WKT, crs); + return new ST_GeomFromTextSpecification( WKT, crs ); } - }
diff --git a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/convert/ST_GeomFromTextSpecification.java b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/convert/ST_GeomFromTextSpecification.java index b7e76a5..eca8444 100644 --- a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/convert/ST_GeomFromTextSpecification.java +++ b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/convert/ST_GeomFromTextSpecification.java
@@ -1,19 +1,18 @@ package org.qi4j.api.query.grammar.extensions.spatial.convert; -import org.qi4j.api.geometry.internal.TGeometry; - +import org.qi4j.api.geometry.TGeometry; public class ST_GeomFromTextSpecification<T extends TGeometry> - extends SpatialConvertSpecification<T> + extends SpatialConvertSpecification { - public ST_GeomFromTextSpecification(String WKT, String crs) + public ST_GeomFromTextSpecification( String WKT, String crs ) { - super(WKT, crs); + super( WKT, crs ); } @Override public String toString() { - return "CONVERTING ( " + geometryAsWKT + " )"; + return "CONVERTING ( " + geometryAsWKT + " )"; } }
diff --git a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/convert/SpatialConvertSpecification.java b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/convert/SpatialConvertSpecification.java index 7e4f13b..aa2e6d9 100644 --- a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/convert/SpatialConvertSpecification.java +++ b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/convert/SpatialConvertSpecification.java
@@ -1,25 +1,22 @@ package org.qi4j.api.query.grammar.extensions.spatial.convert; import org.qi4j.api.composite.Composite; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.query.grammar.ExpressionSpecification; - -public abstract class SpatialConvertSpecification<T> - extends ExpressionSpecification +public abstract class SpatialConvertSpecification + extends ExpressionSpecification { protected String geometryAsWKT; protected TGeometry geometry; protected String crs; - - public SpatialConvertSpecification(String wkt, String crs) + public SpatialConvertSpecification( String wkt, String crs ) { this.geometryAsWKT = wkt; this.crs = crs; } - public String property() { return geometryAsWKT; @@ -30,15 +27,14 @@ return this.geometry; } - public void setGeometry(TGeometry geometry) + public void setGeometry( TGeometry geometry ) { this.geometry = geometry; } @Override - public final boolean satisfiedBy(Composite item) + public final boolean satisfiedBy( Composite item ) { return true; } - }
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 703e955..29549d8 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
@@ -2,37 +2,39 @@ import org.qi4j.api.geometry.TPoint; import org.qi4j.api.geometry.TUnit; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.query.grammar.PropertyFunction; import org.qi4j.api.query.grammar.extensions.spatial.convert.SpatialConvertSpecification; import org.qi4j.functional.Specification; - public class ST_DisjointSpecification<T extends TGeometry> - extends SpatialPredicatesSpecification<T> + extends SpatialPredicatesSpecification<T> { private double distance; private TUnit unit; - public ST_DisjointSpecification(PropertyFunction<T> property, TGeometry param) + public ST_DisjointSpecification( PropertyFunction<T> property, TGeometry param ) { - super(property, param); + super( property, param ); } - public ST_DisjointSpecification(PropertyFunction<T> property, Specification<SpatialConvertSpecification> operator, long distance) + // TODO: [niclas] 'distance' is not used...??? Missing tests? + public ST_DisjointSpecification( PropertyFunction<T> property, + Specification<SpatialConvertSpecification> operator, + long distance + ) { - super(property, operator); + super( property, operator ); } - public ST_DisjointSpecification(PropertyFunction<T> property, TPoint value, double distance, TUnit unit) + public ST_DisjointSpecification( PropertyFunction<T> property, TPoint value, double distance, TUnit unit ) { - super(property, value); + super( property, value ); this.distance = distance; this.unit = unit; } - public double getDistance() { return distance; @@ -43,26 +45,31 @@ return unit; } - @Override - protected boolean compare(TGeometry param) + protected boolean compare( TGeometry param ) { - return param.equals(this.param); + return param.equals( this.param ); } @Override public String toString() { - StringBuffer spec = new StringBuffer(); - spec.append("ST_DISJOINT").append("( ").append(property.toString()).append(" IS NOT WITHIN "); - spec.append(param.toString()); + StringBuilder spec = new StringBuilder(); + spec.append( "ST_DISJOINT" ); + spec.append( "( " ); + spec.append( property.toString() ); + spec.append( " IS NOT WITHIN " ); + spec.append( param.toString() ); - if (distance > 0) + if( distance > 0 ) { - spec.append(" WITH RADIUS ").append(distance).append(" ").append(unit); + spec.append( " WITH RADIUS " ); + spec.append( distance ); + spec.append( " " ); + spec.append( unit ); } - spec.append(" ) "); + spec.append( " ) " ); return spec.toString(); } }
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 6fda01f..93705fa 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
@@ -2,37 +2,37 @@ import org.qi4j.api.geometry.TPoint; import org.qi4j.api.geometry.TUnit; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.query.grammar.PropertyFunction; import org.qi4j.api.query.grammar.extensions.spatial.convert.SpatialConvertSpecification; import org.qi4j.functional.Specification; - public class ST_IntersectsSpecification<T extends TGeometry> - extends SpatialPredicatesSpecification<T> + extends SpatialPredicatesSpecification<T> { - private double distance; private TUnit unit; - public ST_IntersectsSpecification(PropertyFunction<T> property, TGeometry param) + public ST_IntersectsSpecification( PropertyFunction<T> property, TGeometry param ) { - super(property, param); + super( property, param ); } - public ST_IntersectsSpecification(PropertyFunction<T> property, Specification<SpatialConvertSpecification> operator, long distance) + public ST_IntersectsSpecification( PropertyFunction<T> property, + Specification<SpatialConvertSpecification> operator, + long distance + ) { - super(property, operator); + super( property, operator ); } - public ST_IntersectsSpecification(PropertyFunction<T> property, TPoint param, double distance, TUnit unit) + public ST_IntersectsSpecification( PropertyFunction<T> property, TPoint param, double distance, TUnit unit ) { - super(property, param); + super( property, param ); this.distance = distance; this.unit = unit; } - public double getDistance() { return distance; @@ -43,26 +43,31 @@ return unit; } - @Override - protected boolean compare(TGeometry param) + protected boolean compare( TGeometry param ) { - return param.equals(this.param); + return param.equals( this.param ); } @Override public String toString() { - StringBuffer spec = new StringBuffer(); - spec.append("ST_INTERSECTS").append("( ").append(property.toString()).append(" INTERSECTS "); - spec.append(param.toString()); + StringBuilder spec = new StringBuilder(); + spec.append( "ST_INTERSECTS" ); + spec.append( "( " ); + spec.append( property.toString() ); + spec.append( " INTERSECTS " ); + spec.append( param.toString() ); - if (distance > 0) + if( distance > 0 ) { - spec.append(" WITH RADIUS ").append(distance).append(" ").append(unit); + spec.append( " WITH RADIUS " ); + spec.append( distance ); + spec.append( " " ); + spec.append( unit ); } - spec.append(" ) "); + spec.append( " ) " ); return spec.toString(); } }
diff --git a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_WithinSpecification.java b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_WithinSpecification.java index 4483fa6..85522f8 100644 --- a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_WithinSpecification.java +++ b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/ST_WithinSpecification.java
@@ -2,42 +2,44 @@ import org.qi4j.api.geometry.TPoint; import org.qi4j.api.geometry.TUnit; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.query.grammar.PropertyFunction; import org.qi4j.api.query.grammar.extensions.spatial.convert.SpatialConvertSpecification; import org.qi4j.functional.Specification; - public class ST_WithinSpecification<T extends TGeometry> - extends SpatialPredicatesSpecification<T> + extends SpatialPredicatesSpecification<T> { private double distance; private TUnit unit; - public ST_WithinSpecification(PropertyFunction<T> property, TGeometry param) + public ST_WithinSpecification( PropertyFunction<T> property, TGeometry param ) { - super(property, param); + super( property, param ); } - public ST_WithinSpecification(PropertyFunction<T> property, TPoint param, double distance, TUnit unit) + public ST_WithinSpecification( PropertyFunction<T> property, TPoint param, double distance, TUnit unit ) { - super(property, param); + super( property, param ); this.distance = distance; this.unit = unit; } - public ST_WithinSpecification(PropertyFunction<T> property, Specification<SpatialConvertSpecification> operator, double distance, TUnit unit) + public ST_WithinSpecification( PropertyFunction<T> property, + Specification<SpatialConvertSpecification> operator, + double distance, + TUnit unit + ) { - super(property, operator); + super( property, operator ); this.distance = distance; this.unit = unit; } - - public ST_WithinSpecification(PropertyFunction<T> property, Specification<SpatialConvertSpecification> operator) + public ST_WithinSpecification( PropertyFunction<T> property, Specification<SpatialConvertSpecification> operator ) { - super(property, operator); + super( property, operator ); } public double getDistance() @@ -50,26 +52,31 @@ return unit; } - @Override - protected boolean compare(TGeometry param) + protected boolean compare( TGeometry param ) { - return param.equals(this.param); + return param.equals( this.param ); } @Override public String toString() { - StringBuffer spec = new StringBuffer(); - spec.append("ST_WITHIN").append("( ").append(property.toString()).append(" IS WITHIN "); - spec.append(param.toString()); + StringBuilder spec = new StringBuilder(); + spec.append( "ST_WITHIN" ); + spec.append( "( " ); + spec.append( property.toString() ); + spec.append( " IS WITHIN " ); + spec.append( param.toString() ); - if (distance > 0) + if( distance > 0 ) { - spec.append(" WITH RADIUS ").append(distance).append(" ").append(unit); + spec.append( " WITH RADIUS " ); + spec.append( distance ); + spec.append( " " ); + spec.append( unit ); } - spec.append(" ) "); + spec.append( " ) " ); return spec.toString(); } }
diff --git a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/SpatialPredicatesSpecification.java b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/SpatialPredicatesSpecification.java index bd793fb..5bde3e2 100644 --- a/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/SpatialPredicatesSpecification.java +++ b/core/api/src/main/java/org/qi4j/api/query/grammar/extensions/spatial/predicate/SpatialPredicatesSpecification.java
@@ -1,29 +1,30 @@ package org.qi4j.api.query.grammar.extensions.spatial.predicate; import org.qi4j.api.composite.Composite; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.property.Property; import org.qi4j.api.query.grammar.ExpressionSpecification; import org.qi4j.api.query.grammar.PropertyFunction; import org.qi4j.api.query.grammar.extensions.spatial.convert.SpatialConvertSpecification; import org.qi4j.functional.Specification; - public abstract class SpatialPredicatesSpecification<T extends TGeometry> - extends ExpressionSpecification + extends ExpressionSpecification { protected final PropertyFunction<T> property; protected final TGeometry param; protected final Specification<SpatialConvertSpecification> operator; - public SpatialPredicatesSpecification(PropertyFunction<T> property, TGeometry param) + public SpatialPredicatesSpecification( PropertyFunction<T> property, TGeometry param ) { this.property = property; this.param = param; this.operator = null; } - public SpatialPredicatesSpecification(PropertyFunction<T> property, Specification<SpatialConvertSpecification> operator) + public SpatialPredicatesSpecification( PropertyFunction<T> property, + Specification<SpatialConvertSpecification> operator + ) { this.property = property; this.operator = operator; @@ -36,31 +37,32 @@ } @Override - public final boolean satisfiedBy(Composite item) + public final boolean satisfiedBy( Composite item ) { try { - Property<T> prop = property.map(item); + Property<T> prop = property.map( item ); - if (prop == null) + if( prop == null ) { return false; } TGeometry propValue = prop.get(); - if (propValue == null) + if( propValue == null ) { return false; } - return compare(propValue); - } catch (IllegalArgumentException e) + return compare( propValue ); + } + catch( IllegalArgumentException e ) { return false; } } - protected abstract boolean compare(TGeometry value); + protected abstract boolean compare( TGeometry value ); public TGeometry param() {
diff --git a/core/api/src/main/java/org/qi4j/api/type/ValueType.java b/core/api/src/main/java/org/qi4j/api/type/ValueType.java index 8c74442..98c5d01 100644 --- a/core/api/src/main/java/org/qi4j/api/type/ValueType.java +++ b/core/api/src/main/java/org/qi4j/api/type/ValueType.java
@@ -16,7 +16,7 @@ import java.util.Collections; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.util.NullArgumentException; import org.qi4j.functional.Function; import org.qi4j.functional.Iterables;
diff --git a/core/api/src/test/java/org/qi4j/api/geometry/TGeometryFactoryTest.java b/core/api/src/test/java/org/qi4j/api/geometry/TGeometryFactoryTest.java index 1871807..4dc3b76 100644 --- a/core/api/src/test/java/org/qi4j/api/geometry/TGeometryFactoryTest.java +++ b/core/api/src/test/java/org/qi4j/api/geometry/TGeometryFactoryTest.java
@@ -15,9 +15,6 @@ package org.qi4j.api.geometry; import org.junit.Test; -import org.qi4j.api.geometry.internal.Coordinate; -import org.qi4j.api.geometry.internal.TGeometry; -import org.qi4j.api.geometry.internal.TLinearRing; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly; import org.qi4j.test.AbstractQi4jTest;
diff --git a/core/api/src/test/java/org/qi4j/api/geometry/TGeometryTest.java b/core/api/src/test/java/org/qi4j/api/geometry/TGeometryTest.java index 99f0493..f4a56b0 100644 --- a/core/api/src/test/java/org/qi4j/api/geometry/TGeometryTest.java +++ b/core/api/src/test/java/org/qi4j/api/geometry/TGeometryTest.java
@@ -15,10 +15,6 @@ package org.qi4j.api.geometry; import org.junit.Test; -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.api.value.ValueBuilder; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly;
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..1e5f226 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
@@ -18,9 +18,9 @@ package org.qi4j.test.indexing; import org.qi4j.api.geometry.*; -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.geometry.Coordinate; +import org.qi4j.api.geometry.TGeometry; +import org.qi4j.api.geometry.TLinearRing; import org.qi4j.api.unitofwork.UnitOfWork; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly;
diff --git a/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractQueryTest.java b/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractQueryTest.java index 40ceb08..9f39e8a 100644 --- a/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractQueryTest.java +++ b/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractQueryTest.java
@@ -148,11 +148,8 @@ { QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); - Query<Person> query = unitOfWork.newQuery( qb.where( eq( person.mother() - .get() - .placeOfBirth() - .get() - .name(), "Kuala Lumpur" ) ) + Query<Person> query = unitOfWork.newQuery( + qb.where( eq( person.mother().get().placeOfBirth().get().name(), "Kuala Lumpur" ) ) ); System.out.println( "*** script05: " + query ); verifyUnorderedResults( query, "Joe Doe" );
diff --git a/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialQueryTest.java b/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialQueryTest.java index 7bcc39d..50e0fea 100644 --- a/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialQueryTest.java +++ b/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialQueryTest.java
@@ -1,13 +1,21 @@ package org.qi4j.test.indexing; -import org.junit.Test; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import org.qi4j.api.common.Optional; import org.qi4j.api.entity.EntityComposite; -import org.qi4j.api.geometry.*; -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.Service; +import org.qi4j.api.geometry.TFeature; +import org.qi4j.api.geometry.TFeatureCollection; +import org.qi4j.api.geometry.TLineString; +import org.qi4j.api.geometry.TMultiPoint; +import org.qi4j.api.geometry.TMultiPolygon; +import org.qi4j.api.geometry.TPoint; +import org.qi4j.api.geometry.TPolygon; +import org.qi4j.api.geometry.TUnit; +import org.qi4j.api.geometry.Coordinate; +import org.qi4j.api.geometry.TGeometry; +import org.qi4j.api.geometry.TLinearRing; import org.qi4j.api.property.Property; import org.qi4j.api.query.Query; import org.qi4j.api.query.QueryBuilder; @@ -16,10 +24,6 @@ import org.qi4j.bootstrap.ModuleAssembly; import org.qi4j.test.indexing.model.City; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import static org.qi4j.api.query.QueryExpressions.eq; import static org.qi4j.api.query.QueryExpressions.templateFor; import static org.qi4j.api.query.grammar.extensions.spatial.SpatialQueryExpressions.ST_GeometryFromText; @@ -29,7 +33,7 @@ * Created by jakes on 2/8/14. */ public class AbstractSpatialQueryTest - extends AbstractAnyQueryTest + extends AbstractAnyQueryTest { private final String CRS_EPSG_4326 = "EPSG:4326"; @@ -38,71 +42,59 @@ { - @Optional Property<Map<String, Object>> properties(); // @Optional Property<TGeometry> geometry1(); - } - public interface MapFeatureEntity - extends MapFeature, EntityComposite + extends MapFeature, EntityComposite { } - @Override public void assemble( ModuleAssembly module ) - throws AssemblyException + throws AssemblyException { super.assemble( module ); - module.entities(MapFeatureEntity.class); + module.entities( MapFeatureEntity.class ); // internal values - module.values(Coordinate.class, TLinearRing.class, TGeometry.class); + module.values( Coordinate.class, TLinearRing.class, TGeometry.class ); // API values - module.values(TPoint.class, TMultiPoint.class, TLineString.class, TPolygon.class, TMultiPolygon.class, TFeature.class, TFeatureCollection.class); - TGeometry tGeometry = module.forMixin(TGeometry.class).declareDefaults(); - tGeometry.CRS().set(CRS_EPSG_4326); - + module.values( TPoint.class, TMultiPoint.class, TLineString.class, TPolygon.class, TMultiPolygon.class, TFeature.class, TFeatureCollection.class ); + TGeometry tGeometry = module.forMixin( TGeometry.class ).declareDefaults(); + tGeometry.CRS().set( CRS_EPSG_4326 ); } - - // @Test - public void whenQueryUseConversion() throws Exception + public void whenQueryUseConversion() + throws Exception { // lat, long - ST_GeometryFromText("POINT(49.550881 10.712809)"); + ST_GeometryFromText( "POINT(49.550881 10.712809)" ); + QueryBuilder<City> qb = this.module.newQueryBuilder( City.class ); - - QueryBuilder<City> qb = this.module.newQueryBuilder(City.class); - + Property<TPoint> cityLocation = templateFor( City.class ).location(); Query<City> query = unitOfWork.newQuery( - qb - .where( - ST_Within - ( - templateFor(City.class).location(), - ST_GeometryFromText("POINT(49.550881 10.712809)"), - 100, - TUnit.METER - ) - )); - + qb.where( + ST_Within( + cityLocation, + ST_GeometryFromText( "POINT(49.550881 10.712809)" ), + 100, + TUnit.METER + ) + ) + ); // System.out.println( "*** script01: " + query ); query.find(); - - - System.out.println("Found Cities " + query.count()); - + System.out.println( "Found Cities " + query.count() ); // QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); // Person personTemplate = templateFor( Person.class ); @@ -112,8 +104,6 @@ // // verifyUnorderedResults( query, "Joe Doe", "Ann Doe" ); } - - // @Test public void script11() { @@ -123,53 +113,44 @@ // // verifyUnorderedResults( query, "Joe Doe" ); - QueryBuilder<City> qb = this.module.newQueryBuilder( City.class ); City cityTemplate = templateFor( City.class ); // Query<City> query = unitOfWork.newQuery( qb.where( eq( cityTemplate.location(), "Kuala Lumpur" ) ) ); - ValueBuilder<TPolygon> builder = module.newValueBuilder(TPolygon.class); + ValueBuilder<TPolygon> builder = module.newValueBuilder( TPolygon.class ); TPolygon proto = builder.prototype(); List<List<List<Double>>> coordinates = new ArrayList<List<List<Double>>>(); List<List<Double>> a = new ArrayList<List<Double>>(); - a.add(new ArrayList<Double>()); - a.add(new ArrayList<Double>()); - a.add(new ArrayList<Double>()); - coordinates.add(a); + a.add( new ArrayList<Double>() ); + a.add( new ArrayList<Double>() ); + a.add( new ArrayList<Double>() ); + coordinates.add( a ); List<List<Double>> b = new ArrayList<List<Double>>(); - b.add(new ArrayList<Double>()); - b.add(new ArrayList<Double>()); - a.add(new ArrayList<Double>()); - coordinates.add(b); + b.add( new ArrayList<Double>() ); + b.add( new ArrayList<Double>() ); + a.add( new ArrayList<Double>() ); + coordinates.add( b ); // new ArrayList<List<Double>>().add(new ArrayList<Double>()); + coordinates.get( 0 ).get( 0 ).add( 0.0 ); + coordinates.get( 0 ).get( 1 ).add( 0.1 ); + coordinates.get( 0 ).get( 2 ).add( 0.2 ); + coordinates.get( 0 ).get( 3 ).add( 0.3 ); + coordinates.get( 1 ).get( 1 ).add( 1.1 ); - coordinates.get(0).get(0).add(0.0); - coordinates.get(0).get(1).add(0.1); - coordinates.get(0).get(2).add(0.2); - coordinates.get(0).get(3).add(0.3); - - coordinates.get(1).get(1).add(1.1); - - - // proto.coordinates().set(coordinates); - + // proto.coordinates().set(coordinates); //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); // // Query<City> query = unitOfWork.newQuery( @@ -183,7 +164,6 @@ // // System.out.println(query.count()); - // QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); // Person personTemplate = templateFor( Person.class ); // City placeOfBirth = personTemplate.placeOfBirth().get(); @@ -201,7 +181,6 @@ // // verifyUnorderedResults( query, "Joe Doe" ); - // QueryBuilder<City> qb = this.module.newQueryBuilder( City.class ); // City cityTemplate = templateFor( City.class ); // // Query<City> query = unitOfWork.newQuery( qb.where( eq( cityTemplate.location(), "Kuala Lumpur" ) ) ); @@ -243,7 +222,6 @@ //// // verifyUnorderedResults( query, "Joe Doe", "Ann Doe" ); } - // @Test public void script3() { @@ -253,20 +231,17 @@ // // verifyUnorderedResults( query, "Joe Doe" ); - QueryBuilder<City> qb = this.module.newQueryBuilder( City.class ); City cityTemplate = templateFor( City.class ); Query<City> query = unitOfWork.newQuery( qb.where( eq( cityTemplate.name(), "Kuala Lumpur" ) ) ); - System.out.println( "*** script02: " + query ); query.find(); - System.out.println(query.count()); + System.out.println( query.count() ); // System.out.println(query.find().locationABC()); - // QueryBuilder<Person> qb = this.module.newQueryBuilder( Person.class ); // Person personTemplate = templateFor( Person.class ); // City placeOfBirth = personTemplate.placeOfBirth().get(); @@ -276,12 +251,13 @@ } //@Test - public void script4() throws Exception + public void script4() + throws Exception { - System.out.println("Script4"); + System.out.println( "Script4" ); - QueryBuilder<City> qb = this.module.newQueryBuilder(City.class); + QueryBuilder<City> qb = this.module.newQueryBuilder( City.class ); // City cityTemplate = templateFor(City.class); // Query<City> query = unitOfWork.newQuery( @@ -293,7 +269,7 @@ // // )); - // query.find(); + // query.find(); } }
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinder.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinder.java index 3b59443..12b0f83 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinder.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinder.java
@@ -21,43 +21,36 @@ import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.index.query.AndFilterBuilder; import org.elasticsearch.index.query.FilterBuilder; import org.elasticsearch.index.query.OrFilterBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.sort.GeoDistanceSortBuilder; import org.elasticsearch.search.sort.SortOrder; import org.qi4j.api.composite.Composite; import org.qi4j.api.entity.EntityReference; import org.qi4j.api.geometry.*; -import org.qi4j.api.geometry.internal.TGeometry; -import org.qi4j.api.geometry.internal.TLinearRing; +import org.qi4j.api.geometry.TGeometry; +import org.qi4j.api.geometry.TLinearRing; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This; import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.property.GenericPropertyInfo; import org.qi4j.api.query.grammar.*; import org.qi4j.api.query.grammar.extensions.spatial.convert.SpatialConvertSpecification; import org.qi4j.api.query.grammar.extensions.spatial.predicate.SpatialPredicatesSpecification; import org.qi4j.api.structure.Module; -import org.qi4j.api.util.Classes; import org.qi4j.api.value.ValueComposite; import org.qi4j.functional.Function; import org.qi4j.functional.Iterables; import org.qi4j.functional.Specification; import org.qi4j.index.elasticsearch.ElasticSearchFinderSupport.*; import org.qi4j.index.elasticsearch.extensions.spatial.ElasticSearchSpatialFinder; -import org.qi4j.index.elasticsearch.extensions.spatial.functions.convert.ConvertFinderSupport; -import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.PredicateFinderSupport; import org.qi4j.index.elasticsearch.extensions.spatial.internal.InternalUtils; import org.qi4j.spi.query.EntityFinder; import org.qi4j.spi.query.EntityFinderException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.reflect.Type; import java.util.HashMap; import java.util.Map;
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 dee2e26..3981f1a 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
@@ -25,7 +25,7 @@ import org.qi4j.api.association.AssociationDescriptor; import org.qi4j.api.entity.EntityDescriptor; import org.qi4j.api.entity.EntityReference; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.injection.scope.Service; import org.qi4j.api.injection.scope.Structure; import org.qi4j.api.injection.scope.This;
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 c51f31d..2b79993 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
@@ -22,7 +22,7 @@ import org.json.JSONException; import org.json.JSONObject; import org.qi4j.api.geometry.*; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.structure.Module; import org.qi4j.index.elasticsearch.ElasticSearchIndexException; import org.qi4j.index.elasticsearch.ElasticSearchSupport;
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialFunctionsSupportMatrix.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialFunctionsSupportMatrix.java index 90810f3..1d9f7cb 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialFunctionsSupportMatrix.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialFunctionsSupportMatrix.java
@@ -18,7 +18,7 @@ import com.google.common.collect.Table; import org.qi4j.api.geometry.TPoint; import org.qi4j.api.geometry.TPolygon; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_DisjointSpecification; import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_IntersectsSpecification; import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_WithinSpecification;
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Disjoint.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Disjoint.java index 5603bb5..5b3ab50 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Disjoint.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Disjoint.java
@@ -20,7 +20,7 @@ import org.elasticsearch.index.query.GeoPolygonFilterBuilder; import org.qi4j.api.geometry.TPoint; import org.qi4j.api.geometry.TPolygon; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_DisjointSpecification; import org.qi4j.api.query.grammar.extensions.spatial.predicate.SpatialPredicatesSpecification; import org.qi4j.api.structure.Module;
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Intersects.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Intersects.java index a13f1b4..a150ce8 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Intersects.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Intersects.java
@@ -20,7 +20,7 @@ import org.elasticsearch.index.query.GeoPolygonFilterBuilder; import org.qi4j.api.geometry.TPoint; import org.qi4j.api.geometry.TPolygon; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_DisjointSpecification; import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_IntersectsSpecification; import org.qi4j.api.query.grammar.extensions.spatial.predicate.SpatialPredicatesSpecification;
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Within.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Within.java index 1516038..903a0ac 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Within.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_Within.java
@@ -20,7 +20,7 @@ import org.elasticsearch.index.query.GeoPolygonFilterBuilder; import org.qi4j.api.geometry.TPoint; import org.qi4j.api.geometry.TPolygon; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_WithinSpecification; import org.qi4j.api.query.grammar.extensions.spatial.predicate.SpatialPredicatesSpecification; import org.qi4j.api.structure.Module;
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 efcb425..16c61a9 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
@@ -25,8 +25,8 @@ import org.qi4j.api.geometry.TPoint; import org.qi4j.api.geometry.TPolygon; import org.qi4j.api.geometry.TUnit; -import org.qi4j.api.geometry.internal.TCircle; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TCircle; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.property.GenericPropertyInfo; import org.qi4j.api.query.grammar.PropertyFunction; import org.qi4j.api.query.grammar.extensions.spatial.convert.SpatialConvertSpecification;
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/internal/InternalUtils.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/internal/InternalUtils.java index 8b2aa0e..42f2eda 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/internal/InternalUtils.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/internal/InternalUtils.java
@@ -15,7 +15,7 @@ package org.qi4j.index.elasticsearch.extensions.spatial.internal; import org.qi4j.api.geometry.*; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.property.GenericPropertyInfo; import org.qi4j.api.query.grammar.PropertyFunction; import org.qi4j.api.util.Classes;
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/mappings/SpatialIndexMapper.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/mappings/SpatialIndexMapper.java index 87e7a08..ad597d6 100644 --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/mappings/SpatialIndexMapper.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/mappings/SpatialIndexMapper.java
@@ -14,7 +14,7 @@ package org.qi4j.index.elasticsearch.extensions.spatial.mappings; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.index.elasticsearch.ElasticSearchSupport; import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialConfiguration; import org.qi4j.index.elasticsearch.extensions.spatial.mappings.cache.MappingsCachesTable;
diff --git a/libraries/geometry/build.gradle b/libraries/geometry/build.gradle new file mode 100644 index 0000000..8bfe036 --- /dev/null +++ b/libraries/geometry/build.gradle
@@ -0,0 +1,13 @@ +description = "Qi4j library for add-ons to the GeoSpatial support in Qi4j Core." + +jar { manifest { name = "Qi4j Library - GeoSpatial" }} + +dependencies { + compile(project(":org.qi4j.core:org.qi4j.core.api")) + compile(project(":org.qi4j.core:org.qi4j.core.bootstrap")) + + testCompile(project(":org.qi4j.core:org.qi4j.core.testsupport")) + + testRuntime(project(":org.qi4j.core:org.qi4j.core.runtime")) + testRuntime(libraries.logback) +} \ No newline at end of file
diff --git a/libraries/geometry/dev-status.xml b/libraries/geometry/dev-status.xml new file mode 100644 index 0000000..55cc45b --- /dev/null +++ b/libraries/geometry/dev-status.xml
@@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<module xmlns="http://www.qi4j.org/schemas/2008/dev-status/1" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.qi4j.org/schemas/2008/dev-status/1 + http://www.qi4j.org/schemas/2008/dev-status/1/dev-status.xsd"> + <status> + <!--none,early,beta,stable,mature--> + <codebase>early</codebase> + + <!-- none, brief, good, complete --> + <documentation>none</documentation> + + <!-- none, some, good, complete --> + <unittests>none</unittests> + </status> + <licenses> + <license>ALv2</license> + </licenses> +</module>
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/TGeometryBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/TGeometryBuilder.java new file mode 100644 index 0000000..e1aa85f --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/TGeometryBuilder.java
@@ -0,0 +1,31 @@ +package org.qi4j.library.geometry; + +import org.qi4j.api.geometry.TFeature; +import org.qi4j.api.injection.scope.Structure; +import org.qi4j.api.structure.Module; +import org.qi4j.api.value.ValueBuilder; + +public class TGeometryBuilder<T> +{ + @Structure + private Module module; + + private ValueBuilder<T> builder; + private T geometry; + + public TGeometryBuilder(Class<T> type) + { + builder = module.newValueBuilder( type ); + geometry = builder.prototype(); + } + + public T geometry() + { + return geometry; + } + + public T newInstance() + { + return builder.newInstance(); + } +}
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/TGeometryFactory.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/TGeometryFactory.java new file mode 100644 index 0000000..bc2bb0b --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/TGeometryFactory.java
@@ -0,0 +1,95 @@ +package org.qi4j.library.geometry; + +import org.qi4j.api.injection.scope.Structure; +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.structure.Module; +import org.qi4j.library.geometry.builders.TCRSBuilder; +import org.qi4j.library.geometry.builders.TFeatureBuilder; +import org.qi4j.library.geometry.builders.TFeatureCollectionBuilder; +import org.qi4j.library.geometry.builders.TLineStringBuilder; +import org.qi4j.library.geometry.builders.TLinearRingBuilder; +import org.qi4j.library.geometry.builders.TMultiLineStringBuilder; +import org.qi4j.library.geometry.builders.TMultiPointBuilder; +import org.qi4j.library.geometry.builders.TMultiPolygonsBuilder; +import org.qi4j.library.geometry.builders.TPointBuilder; +import org.qi4j.library.geometry.builders.TPolygonBuilder; + +@Mixins( TGeometryFactory.Mixin.class ) +public interface TGeometryFactory +{ + TCRSBuilder TCrs(); + + TPointBuilder TPoint(); + + TMultiPointBuilder TMultiPoint(); + + TLinearRingBuilder TLinearRing(); + + TLineStringBuilder TLineString(); + + TMultiLineStringBuilder TMultiLineString(); + + TPolygonBuilder TPolygon(); + + TMultiPolygonsBuilder TMultiPolygon(); + + TFeatureBuilder TFeature(); + + TFeatureCollectionBuilder TFeatureCollection(); + + class Mixin implements TGeometryFactory + { + @Structure + private Module module; + + public TCRSBuilder TCrs() + { + return new TCRSBuilder( module ); + } + + public TPointBuilder TPoint() + { + return new TPointBuilder( module ); + } + + public TMultiPointBuilder TMultiPoint() + { + return new TMultiPointBuilder( module ); + } + + public TLinearRingBuilder TLinearRing() + { + return new TLinearRingBuilder( module ); + } + + public TLineStringBuilder TLineString() + { + return new TLineStringBuilder( module ); + } + + public TMultiLineStringBuilder TMultiLineString() + { + return new TMultiLineStringBuilder( module ); + } + + public TPolygonBuilder TPolygon() + { + return new TPolygonBuilder( module ); + } + + public TMultiPolygonsBuilder TMultiPolygon() + { + return new TMultiPolygonsBuilder( module ); + } + + public TFeatureBuilder TFeature() + { + return new TFeatureBuilder( module ); + } + + public TFeatureCollectionBuilder TFeatureCollection() + { + return new TFeatureCollectionBuilder( module ); + } + } +}
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TCRSBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TCRSBuilder.java similarity index 64% rename from core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TCRSBuilder.java rename to libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TCRSBuilder.java index e089b5a..211aba1 100644 --- a/core/api/src/main/java/org/qi4j/api/geometry/internal/builders/TCRSBuilder.java +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TCRSBuilder.java
@@ -12,28 +12,20 @@ * */ -package org.qi4j.api.geometry.internal.builders; +package org.qi4j.library.geometry.builders; import org.qi4j.api.geometry.TCRS; -import org.qi4j.api.structure.Module; +import org.qi4j.library.geometry.TGeometryBuilder; -public class TCRSBuilder +public class TCRSBuilder extends TGeometryBuilder<TCRS> { - - private Module module; - private TCRS geometry; - - - public TCRSBuilder(Module module) + public TCRSBuilder() { - this.module = module; - geometry = module.newValueBuilder(TCRS.class).prototype(); + super( TCRS.class ); } - public TCRS crs(String crs) + public TCRS crs( String crs ) { - return geometry.of(crs); + return geometry().of( crs ); } - - }
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TFeatureBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TFeatureBuilder.java new file mode 100644 index 0000000..0df7fd9 --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TFeatureBuilder.java
@@ -0,0 +1,45 @@ +/* + * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. + * + * 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.geometry.builders; + +import org.qi4j.api.geometry.TFeature; +import org.qi4j.api.geometry.TGeometry; +import org.qi4j.library.geometry.TGeometryBuilder; + +public class TFeatureBuilder extends TGeometryBuilder<TFeature> +{ + public TFeatureBuilder() + { + super( TFeature.class ); + } + + public TFeatureBuilder of( TGeometry feature ) + { + geometry().of( feature ); + return this; + } + + public TFeatureBuilder addProperty( String name, String value ) + { + geometry().addProperty( name, value ); + return this; + } + + + public TFeature geometry( int srid ) + { + return geometry(); + } +}
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TFeatureCollectionBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TFeatureCollectionBuilder.java new file mode 100644 index 0000000..39897de --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TFeatureCollectionBuilder.java
@@ -0,0 +1,46 @@ +/* + * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. + * + * 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.geometry.builders; + +import java.util.List; +import org.qi4j.api.geometry.TFeature; +import org.qi4j.api.geometry.TFeatureCollection; +import org.qi4j.api.structure.Module; +import org.qi4j.library.geometry.TGeometryBuilder; + +public class TFeatureCollectionBuilder extends TGeometryBuilder<TFeatureCollection> +{ + public TFeatureCollectionBuilder() + { + super(TFeatureCollection.class); + } + + public TFeatureCollectionBuilder of( List<TFeature> features ) + { + geometry().of( features ); + return this; + } + + public TFeatureCollectionBuilder of( TFeature... features ) + { + geometry().of( features ); + return this; + } + + public TFeatureCollection geometry( int srid ) + { + return geometry(); + } +}
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TLineStringBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TLineStringBuilder.java new file mode 100644 index 0000000..aa0499b --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TLineStringBuilder.java
@@ -0,0 +1,57 @@ +/* + * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. + * + * 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.geometry.builders; + +import org.qi4j.api.geometry.TLineString; +import org.qi4j.api.geometry.TPoint; +import org.qi4j.library.geometry.TGeometryBuilder; + +public class TLineStringBuilder extends TGeometryBuilder<TLineString> +{ + public TLineStringBuilder() + { + super( TLineString.class ); + } + + public TLineStringBuilder points( double[][] points ) + { + for( double yx[] : points ) + { + if( yx.length < 2 ) + { + return null; + } + geometry().yx( yx[ 0 ], yx[ 1 ] ); + } + return this; + } + + public TLineStringBuilder of( TPoint... points ) + { + geometry().of( points ); + return this; + } + + public TLineStringBuilder of() + { + geometry().of(); + return this; + } + + public TLineString geometry( int srid ) + { + return geometry(); + } +}
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TLinearRingBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TLinearRingBuilder.java new file mode 100644 index 0000000..0af807a --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TLinearRingBuilder.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. + * + * 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.geometry.builders; + +import org.qi4j.api.geometry.TPoint; +import org.qi4j.api.geometry.TLinearRing; +import org.qi4j.library.geometry.TGeometryBuilder; + +public class TLinearRingBuilder extends TGeometryBuilder<TLinearRing> +{ + public TLinearRingBuilder() + { + super( TLinearRing.class ); + } + + public TLinearRingBuilder ring( double[][] ring ) + { + for( double xy[] : ring ) + { + if( xy.length < 2 ) + { + return null; + } + geometry().yx( xy[ 0 ], xy[ 1 ] ); + } + return this; + } + + public TLinearRingBuilder of( TPoint... points ) + { + geometry().of( points ); + return this; + } + + public TLinearRing geometry( int srid ) + { + return geometry(); + } +}
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TMultiLineStringBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TMultiLineStringBuilder.java new file mode 100644 index 0000000..eb16d6a --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TMultiLineStringBuilder.java
@@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. + * + * 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.geometry.builders; + +import java.util.List; +import org.qi4j.api.geometry.TLineString; +import org.qi4j.api.geometry.TMultiLineString; +import org.qi4j.api.structure.Module; +import org.qi4j.library.geometry.TGeometryBuilder; + +public class TMultiLineStringBuilder extends TGeometryBuilder<TMultiLineString> +{ + public TMultiLineStringBuilder( ) + { + super( TMultiLineString.class ); + } + + public TMultiLineStringBuilder points( double[][][] points ) + { + for( double xy[][] : points ) + { + if( xy.length < 2 ) + { + return null; + } + } + return this; + } + + public TMultiLineStringBuilder of( List<TLineString> lines ) + { + geometry().of( lines ); + return this; + } + + public TMultiLineStringBuilder of( TLineString... lines ) + { + geometry().of( lines ); + return this; + } + + public TMultiLineString geometry( int srid ) + { + return geometry(); + } +}
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TMultiPointBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TMultiPointBuilder.java new file mode 100644 index 0000000..c5311fb --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TMultiPointBuilder.java
@@ -0,0 +1,54 @@ +/* + * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. + * + * 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.geometry.builders; + +import org.qi4j.api.geometry.TMultiPoint; +import org.qi4j.api.geometry.TPoint; +import org.qi4j.api.structure.Module; +import org.qi4j.library.geometry.TGeometryBuilder; + +public class TMultiPointBuilder extends TGeometryBuilder<TMultiPoint> +{ + public TMultiPointBuilder( Module module ) + { + super( TMultiPoint.class ); + } + + // Format { lat, lon } + public TMultiPointBuilder points( double[][] points ) + { + for( double yx[] : points ) + { + if( yx.length < 2 ) + { + return null; + } + geometry().yx( yx[ 0 ], yx[ 1 ] ); + } + return this; + } + + public TMultiPointBuilder of( TPoint... points ) + { + geometry().of( points ); + return this; + } + + public TMultiPoint geometry( String CRS ) + { + geometry().setCRS( CRS ); + return geometry(); + } +}
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TMultiPolygonsBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TMultiPolygonsBuilder.java new file mode 100644 index 0000000..26be8ea --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TMultiPolygonsBuilder.java
@@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. + * + * 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.geometry.builders; + +import java.util.List; +import org.qi4j.api.geometry.TMultiPolygon; +import org.qi4j.api.geometry.TPolygon; +import org.qi4j.api.structure.Module; +import org.qi4j.library.geometry.TGeometryBuilder; + +public class TMultiPolygonsBuilder extends TGeometryBuilder<TMultiPolygon> +{ + public TMultiPolygonsBuilder( ) + { + super(TMultiPolygon.class); + } + + public TMultiPolygonsBuilder points( double[][][] points ) + { + for( double xy[][] : points ) + { + if( xy.length < 2 ) + { + return null; + } + } + return this; + } + + public TMultiPolygonsBuilder of( List<TPolygon> polygons ) + { + geometry().of( polygons ); + return this; + } + + public TMultiPolygonsBuilder of( TPolygon... polygons ) + { + geometry().of( polygons ); + return this; + } + + public TMultiPolygon geometry( int srid ) + { + return geometry(); + } +}
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TPointBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TPointBuilder.java new file mode 100644 index 0000000..f12acfb --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TPointBuilder.java
@@ -0,0 +1,75 @@ +/* + * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. + * + * 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.geometry.builders; + +import org.qi4j.api.geometry.TPoint; +import org.qi4j.api.geometry.TGeometry; +import org.qi4j.api.structure.Module; +import org.qi4j.library.geometry.TGeometryBuilder; + +public class TPointBuilder extends TGeometryBuilder<TPoint> +{ + public TPointBuilder( Module module ) + { + super(TPoint.class); + } + + public TPointBuilder x( double x ) + { + geometry().x( x ); + return this; + } + + public TPointBuilder y( double y ) + { + geometry().y( y ); + return this; + } + + public TPointBuilder z( double u ) + { + geometry().z( u ); + return this; + } + + public TPointBuilder lat( double lat ) + { + geometry().y( lat ); + return this; + } + + public TPointBuilder lon( double lon ) + { + geometry().x( lon ); + return this; + } + + public TPointBuilder alt( double alt ) + { + geometry().z( alt ); + return this; + } + + public boolean isPoint( TGeometry tGeometry ) + { + return tGeometry instanceof TPoint; + } + + public TPoint geometry( String CRS ) + { + geometry().setCRS( CRS ); + return geometry(); + } +}
diff --git a/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TPolygonBuilder.java b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TPolygonBuilder.java new file mode 100644 index 0000000..873c522 --- /dev/null +++ b/libraries/geometry/src/main/java/org/qi4j/library/geometry/builders/TPolygonBuilder.java
@@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014, Jiri Jetmar. All Rights Reserved. + * + * 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.geometry.builders; + +import org.qi4j.api.geometry.TPolygon; +import org.qi4j.api.geometry.TLinearRing; +import org.qi4j.api.injection.scope.Structure; +import org.qi4j.api.structure.Module; +import org.qi4j.library.geometry.TGeometryBuilder; + +public class TPolygonBuilder extends TGeometryBuilder<TPolygon> +{ + @Structure + private Module module; + + public TPolygonBuilder() + { + super( TPolygon.class ); + } + + public TPolygonBuilder shell( TLinearRing shell ) + { + geometry().of( shell ); + return this; + } + + public TPolygonBuilder shell( double[][] shell ) + { + geometry().of( module.newObject( TLinearRingBuilder.class ).ring( shell ).geometry() ); + return this; + } + + public TPolygonBuilder withHoles( TLinearRing... holes ) + { + geometry().withHoles( holes ); + return this; + } + + public TPolygon geometry( String CRS ) + { + geometry().setCRS( CRS ); + return geometry(); + } +}
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 index 815e198..2ff1c0b 100644 --- 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
@@ -21,10 +21,10 @@ 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.api.geometry.Coordinate; +import org.qi4j.api.geometry.TCircle; +import org.qi4j.api.geometry.TGeometry; +import org.qi4j.api.geometry.TLinearRing; import org.qi4j.bootstrap.Assemblers; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly;
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/FromHelper.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/FromHelper.java index 68ab3d9..1ff57da 100644 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/FromHelper.java +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/FromHelper.java
@@ -19,7 +19,7 @@ package org.qi4j.library.spatial.formats.conversions.from; import org.geojson.GeoJsonObject; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.structure.Module; import org.qi4j.library.spatial.formats.conversions.to.ToHelper;
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/GeoJsonFromConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/GeoJsonFromConverter.java index 70bbdb0..149ef02 100644 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/GeoJsonFromConverter.java +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/GeoJsonFromConverter.java
@@ -20,8 +20,8 @@ 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.geometry.TGeometry; +import org.qi4j.api.geometry.TLinearRing; import org.qi4j.api.structure.Module; import java.util.List;
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/TGeometryFromConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/TGeometryFromConverter.java index 2c05866..f5637d4 100644 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/TGeometryFromConverter.java +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/TGeometryFromConverter.java
@@ -18,7 +18,7 @@ package org.qi4j.library.spatial.formats.conversions.from; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.structure.Module;
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/WKTFromConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/WKTFromConverter.java index 5719376..0223802 100644 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/WKTFromConverter.java +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/WKTFromConverter.java
@@ -32,8 +32,8 @@ 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.geometry.TGeometry; +import org.qi4j.api.geometry.TLinearRing; import org.qi4j.api.structure.Module; import org.qi4j.api.value.ValueBuilder;
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/GeoJsonToConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/GeoJsonToConverter.java index 366c98f..17af07a 100644 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/GeoJsonToConverter.java +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/GeoJsonToConverter.java
@@ -21,7 +21,7 @@ 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.geometry.TGeometry; import org.qi4j.api.structure.Module;
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/Spatial4JToConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/Spatial4JToConverter.java index 27e2237..525dbbb 100644 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/Spatial4JToConverter.java +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/Spatial4JToConverter.java
@@ -30,8 +30,8 @@ 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.geometry.TCircle; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.structure.Module;
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/TGeometryToConverter.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/TGeometryToConverter.java index c80c06c..9602a5a 100644 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/TGeometryToConverter.java +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/TGeometryToConverter.java
@@ -18,7 +18,7 @@ package org.qi4j.library.spatial.formats.conversions.to; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.structure.Module; /**
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/ToHelper.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/ToHelper.java index 4103075..eca8bc6 100644 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/ToHelper.java +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/ToHelper.java
@@ -19,7 +19,7 @@ package org.qi4j.library.spatial.formats.conversions.to; import org.geojson.GeoJsonObject; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.structure.Module; import static org.qi4j.library.spatial.projections.transformations.TTransformations.Transform;
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/FromHelper.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/FromHelper.java index f3ebe56..089f074 100644 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/FromHelper.java +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/FromHelper.java
@@ -18,7 +18,7 @@ package org.qi4j.library.spatial.projections.transformations.fromto; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.structure.Module; import org.qi4j.library.spatial.formats.conversions.from.TGeometryFromConverter;
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/ToHelper.java b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/ToHelper.java index eb49068..d95f3c9 100644 --- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/ToHelper.java +++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/ToHelper.java
@@ -23,8 +23,8 @@ import org.cts.op.CoordinateOperation; import org.cts.op.CoordinateOperationFactory; import org.qi4j.api.geometry.*; -import org.qi4j.api.geometry.internal.Coordinate; -import org.qi4j.api.geometry.internal.TGeometry; +import org.qi4j.api.geometry.Coordinate; +import org.qi4j.api.geometry.TGeometry; import org.qi4j.api.structure.Module; import org.qi4j.library.spatial.projections.ProjectionsRegistry; import org.slf4j.Logger;
diff --git a/settings.gradle b/settings.gradle index 2779ea2..c2d3d40 100644 --- a/settings.gradle +++ b/settings.gradle
@@ -14,6 +14,7 @@ 'libraries:eventsourcing-jdbm', 'libraries:eventsourcing-rest', 'libraries:fileconfig', + 'libraries:geometry', 'libraries:http', 'libraries:invocation-cache', 'libraries:lang-beanshell',