private GeometryFactory getGeometryFactory() { if (geomFac == null) { geomFac = new GeometryFactory(new LiteCoordinateSequenceFactory()); } return geomFac; }
public void testCreateSchemaAndInsertPolyRectangle() throws Exception { LiteCoordinateSequenceFactory csf = new LiteCoordinateSequenceFactory(); GeometryFactory gf = new GeometryFactory(csf); LinearRing shell = gf.createLinearRing( csf.create( new double[] {0, 0, 99, 1, 0, 33, 1, 1, 66, 0, 1, 33, 0, 0, 99}, 3)); Polygon poly = gf.createPolygon(shell, null); checkCreateSchemaAndInsert(poly); }
/** * Creates a LineString using a LiteCoordinateSequence with 2 3D coordinates. * * @return a 3D LineString */ public static LineString lineStringLite3D() { return liteGF.createLineString(liteCSF.create(new double[] {1, 2, 100, 3, 4, 200}, 3)); }
LiteCoordinateSequence seq = LiteCoordinateSequenceFactory.lite(originalSequence); boolean loop = ls instanceof LinearRing; if (!loop && seq.size() > 1) {
/** * Builds an array of JTS <code>Coordinate</code> instances that's geometrically equals to the * <code>SeShape</code> single coordinates array passed as argument. * * @param coordList array of coordinates of a single shape part to build a <code>Coordinate * </code> from * @return a geometrically equal to <code>coordList</code> array of <code>Coordinate</code> * instances */ protected final CoordinateSequence toCoords( double[] coordList, final CoordinateSequenceFactory csFact) { final int dimension = 2; CoordinateSequence cs; if (csFact instanceof LiteCoordinateSequenceFactory) { cs = ((LiteCoordinateSequenceFactory) csFact).create(coordList, dimension); } else { final int nCoords = coordList.length / dimension; cs = JTS.createCS(csFact, nCoords, dimension); for (int coordN = 0; coordN < nCoords; coordN++) { cs.setOrdinate(coordN, 0, coordList[dimension * coordN]); cs.setOrdinate(coordN, 1, coordList[dimension * coordN + 1]); } } return cs; }
private GeometryFactory getGeometryFactory(final Hints queryHints) { // setup the geometry factory according to the hints final Hints hints; if (queryHints == null) { hints = GeoTools.getDefaultHints(); } else { hints = queryHints; } GeometryFactory gf = (GeometryFactory) hints.get(Hints.JTS_GEOMETRY_FACTORY); if (gf == null) { PrecisionModel pm = (PrecisionModel) hints.get(Hints.JTS_PRECISION_MODEL); if (pm == null) { pm = new PrecisionModel(); } Integer SRID = (Integer) hints.get(Hints.JTS_SRID); int srid = SRID == null ? 0 : SRID.intValue(); Integer dimension = (Integer) hints.get(Hints.COORDINATE_DIMENSION); CoordinateSequenceFactory csFactory = (CoordinateSequenceFactory) hints.get(Hints.JTS_COORDINATE_SEQUENCE_FACTORY); if (csFactory == null) { if (dimension == null || dimension <= 3) { csFactory = CoordinateArraySequenceFactory.instance(); } else { csFactory = new LiteCoordinateSequenceFactory(); } } gf = new GeometryFactory(pm, srid, csFactory); } return gf; }
public void testCreateSchemaAndInsertPolyRectangleWithHole() throws Exception { LiteCoordinateSequenceFactory csf = new LiteCoordinateSequenceFactory(); GeometryFactory gf = new GeometryFactory(csf); LinearRing shell = gf.createLinearRing( csf.create( new double[] {0, 0, 99, 10, 0, 33, 10, 10, 66, 0, 10, 66, 0, 0, 99}, 3)); LinearRing hole = gf.createLinearRing( csf.create( new double[] {2, 2, 99, 3, 2, 44, 3, 3, 99, 2, 3, 99, 2, 2, 99}, 3)); Polygon poly = gf.createPolygon(shell, new LinearRing[] {hole}); checkCreateSchemaAndInsert(poly); }
/** * Creates a Polygon using a LiteCoordinateSequence with 2D coordinates. * * @return a 2D Polygon */ public static Polygon polygonLite2D() { return liteGF.createPolygon( liteGF.createLinearRing( liteCSF.create(new double[] {1, 1, 2, 1, 2, 2, 1, 2, 1, 1}, 2)), null); }
/** * Makes sure the datastore works when the renderer uses the typical rendering hints * * @throws Exception */ public void testRendererBehaviour() throws Exception { Query query = new Query(featureSource.getSchema().getTypeName()); query.setHints( new Hints( new Hints( Hints.JTS_COORDINATE_SEQUENCE_FACTORY, new LiteCoordinateSequenceFactory()))); SimpleFeatureCollection fc = featureSource.getFeatures(query); try (SimpleFeatureIterator fi = fc.features()) { while (fi.hasNext()) { fi.next(); } } }
public void testCreateSchemaAndInsertPolyWithHoleCW() throws Exception { LiteCoordinateSequenceFactory csf = new LiteCoordinateSequenceFactory(); GeometryFactory gf = new GeometryFactory(csf); LinearRing shell = gf.createLinearRing( csf.create( new double[] {1, 1, 99, 10, 1, 33, 10, 10, 66, 1, 10, 66, 1, 1, 99}, 3)); LinearRing hole = gf.createLinearRing( csf.create( new double[] {2, 2, 99, 8, 2, 44, 8, 8, 99, 2, 8, 99, 2, 2, 99}, 3)); Polygon poly = gf.createPolygon(shell, new LinearRing[] {hole}); checkCreateSchemaAndInsert(poly); }
/** * Creates a Polygon using a LiteCoordinateSequence with 3D coordinates. * * @return a 3D Polygon */ public static Polygon polygonLite3D() { return liteGF.createPolygon( liteGF.createLinearRing( liteCSF.create( new double[] {1, 1, 100, 2, 1, 99, 2, 2, 98, 1, 2, 97, 1, 1, 100}, 3)), null); }
private GeometryFactory getGeometryFactory() { if (geomFac == null) { geomFac = new GeometryFactory(new LiteCoordinateSequenceFactory()); } return geomFac; }
public void testCreateSchemaAndInsertPolyTriangle() throws Exception { LiteCoordinateSequenceFactory csf = new LiteCoordinateSequenceFactory(); GeometryFactory gf = new GeometryFactory(csf); LinearRing shell = gf.createLinearRing( csf.create(new double[] {0, 0, 99, 1, 0, 33, 1, 1, 66, 0, 0, 99}, 3)); Polygon poly = gf.createPolygon(shell, null); checkCreateSchemaAndInsert(poly); }
@Test public void testCoordinateDimensionLineStringLite3D() { Geometry geom = liteGF.createLineString(liteCSF.create(new double[] {1, 2, 100, 3, 4, 200}, 3)); assertEquals(3, CoordinateSequences.coordinateDimension(geom)); }
private GeometryFactory getGeometryFactory() { if (geomFac == null) { geomFac = new GeometryFactory(new LiteCoordinateSequenceFactory()); } return geomFac; }
public void testCloning() throws TransformException, FactoryException { LiteCoordinateSequenceFactory csFac = new LiteCoordinateSequenceFactory(); GeometryFactory geomFac = new GeometryFactory(csFac); CoordinateSequence cs = csFac.create(4, 2); cs.setOrdinate(0, 0, 10); cs.setOrdinate(0, 1, 10); cs.setOrdinate(1, 0, 12); cs.setOrdinate(1, 1, 12); cs.setOrdinate(2, 0, 14); cs.setOrdinate(2, 1, 12); cs.setOrdinate(3, 0, 30); cs.setOrdinate(3, 1, 10); LineString ls = geomFac.createLineString(cs); LineString copy = (LineString) ls.copy(); LiteShape2 ltCloning = new LiteShape2( ls, ProjectiveTransform.create(AffineTransform.getScaleInstance(10, 10)), new Decimator(4, 4), true); assertTrue(ls.equalsExact(copy)); LiteShape2 ltNotCloning = new LiteShape2( ls, ProjectiveTransform.create(AffineTransform.getScaleInstance(10, 10)), new Decimator(4, 4), true, false); assertFalse(ls.equalsExact(copy)); }
@Test public void testCoordinateDimensionPolygonEmptyLite3D() { Geometry geom = liteGF.createPolygon( liteGF.createLinearRing(liteCSF.create(new double[0], 3)), null); assertEquals(3, CoordinateSequences.coordinateDimension(geom)); }
@Test public void testTransformExtraMZ() throws Exception { LiteCoordinateSequence cs = new LiteCoordinateSequence(1, 4); cs.setArray(new double[] {1000000, 4000000, 25, 48}); CoordinateReferenceSystem sourceCrs = CRS.parseWKT(JTSTest.UTM_ZONE_10N); CoordinateReferenceSystem destCrs = DefaultGeographicCRS.WGS84; DefaultCoordinateSequenceTransformer cst; cst = new DefaultCoordinateSequenceTransformer(new LiteCoordinateSequenceFactory()); MathTransform tx = CRS.findMathTransform(sourceCrs, destCrs, true); LiteCoordinateSequence transformed = (LiteCoordinateSequence) cst.transform(cs, tx); assertEquals(25.0, transformed.getOrdinate(0, 2), 0.0); assertEquals(48.0, transformed.getOrdinate(0, 3), 0.0); }
@Test public void testDistance() throws Exception { LineString ls = gf.createLineString(csf.create(new double[] {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5})); Decimator d = new Decimator(identity, new Rectangle(0, 0, 5, 5), 0.8); d.decimateTransformGeneralize((Geometry) ls.copy(), identity); assertEquals(6, ls.getNumPoints()); d = new Decimator(identity, new Rectangle(0, 0, 5, 5), 1); d.decimateTransformGeneralize(ls, identity); assertEquals(4, ls.getNumPoints()); d = new Decimator(identity, new Rectangle(0, 0, 5, 5), 6); d.decimateTransformGeneralize(ls, identity); assertEquals(2, ls.getNumPoints()); }
public void testGeometryFactoryHintsCS() throws IOException { SimpleFeatureSource fs = dataStore.getFeatureSource(tname("road")); assertTrue(fs.getSupportedHints().contains(Hints.JTS_COORDINATE_SEQUENCE_FACTORY)); Query q = new Query(tname("road")); Hints hints = new Hints( Hints.JTS_COORDINATE_SEQUENCE_FACTORY, new LiteCoordinateSequenceFactory()); q.setHints(hints); try (SimpleFeatureIterator it = fs.getFeatures(q).features()) { it.hasNext(); SimpleFeature f = (SimpleFeature) it.next(); LineString ls = (LineString) f.getDefaultGeometry(); assertTrue(ls.getCoordinateSequence() instanceof LiteCoordinateSequence); } }