org.locationtech.jts.geom.Polygon Java Examples
The following examples show how to use
org.locationtech.jts.geom.Polygon.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LasInfoController.java From hortonmachine with GNU General Public License v3.0 | 7 votes |
private void createOverviewAction( File saveFile ) { String outputFilePath = saveFile.getAbsolutePath(); ILasHeader header = lasReader.getHeader(); long recordsCount = header.getRecordsCount(); int work = (int) (recordsCount / 1000); new ExecutorProgressGui(work * 2){ @Override public void backGroundWork() throws Exception { constraints.applyConstraints(lasReader, true, this); publish(new ProgressUpdate("Getting bounds...", work + work / 2)); Envelope filteredEnvelope = constraints.getFilteredEnvelope(); Polygon polygon = GeometryUtilities.createPolygonFromEnvelope(filteredEnvelope); polygon.setUserData("Overview for " + lasReader.getLasFile().getName()); SimpleFeatureCollection fc = FeatureUtilities.featureCollectionFromGeometry(header.getCrs(), polygon); String f = outputFilePath; if (!f.toLowerCase().endsWith(".shp")) f = f + ".shp"; OmsVectorWriter.writeVector(f, fc); done(); } }.execute(); }
Example #2
Source File: LasIndexer.java From hortonmachine with GNU General Public License v3.0 | 7 votes |
public static Polygon envelopeToPolygon( Envelope envelope ) { double w = envelope.getMinX(); double e = envelope.getMaxX(); double s = envelope.getMinY(); double n = envelope.getMaxY(); Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(w, n); coords[1] = new Coordinate(e, n); coords[2] = new Coordinate(e, s); coords[3] = new Coordinate(w, s); coords[4] = new Coordinate(w, n); GeometryFactory gf = GeometryUtilities.gf(); LinearRing linearRing = gf.createLinearRing(coords); Polygon polygon = gf.createPolygon(linearRing, null); return polygon; }
Example #3
Source File: ExportGeometryActionTest.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Test public void testWritingShapeFile_Geometry() throws Exception { SimpleFeatureType sft = createPlainFeatureType("Polygon", Geometry.class, DefaultGeographicCRS.WGS84); GeometryFactory gf = new GeometryFactory(); Polygon polygon = gf.createPolygon(gf.createLinearRing(new Coordinate[]{ new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(0, 1), new Coordinate(0, 0), }), null); SimpleFeature polygonFeature = createPlainFeature(sft, "_1", polygon, ""); ArrayList<SimpleFeature> features = new ArrayList<>(); features.add(polygonFeature); Class<Polygon> geomType = Polygon.class; doExportImport(features, geomType); }
Example #4
Source File: GeometryConverterAdapter.java From importer-exporter with Apache License 2.0 | 6 votes |
private Polygon convertPolygonToJTS(GeometryObject geomObj) { double[][] coordinates = geomObj.getCoordinates(); int dimension = geomObj.getDimension(); LinearRing shell = null; LinearRing[] holes = geomObj.getNumElements() - 1 > 0 ? new LinearRing[geomObj.getNumElements() - 1] : null; for (int i = 0; i < coordinates.length; i++) { LinearRing ring = factory.createLinearRing(getCoordinatesArray(coordinates[i], dimension)); if (i == 0) shell = ring; else holes[i - 1] = ring; } return factory.createPolygon(shell, holes); }
Example #5
Source File: JTSHelperTest.java From arctic-sea with Apache License 2.0 | 6 votes |
@Test public void shouldReverseMultiPolygon() throws OwsExceptionReport { final GeometryFactory factory = getGeometryFactoryForSRID(4326); testReverse(factory.createMultiPolygon(new Polygon[]{ factory.createPolygon( factory.createLinearRing(randomCoordinateRing(13)), new LinearRing[]{factory.createLinearRing(randomCoordinateRing(130)), factory.createLinearRing(randomCoordinateRing(4121)), factory.createLinearRing(randomCoordinateRing(12))}), factory.createPolygon( factory.createLinearRing(randomCoordinateRing(8)), new LinearRing[]{factory.createLinearRing(randomCoordinateRing(1101)), factory.createLinearRing(randomCoordinateRing(413)), factory.createLinearRing(randomCoordinateRing(123))}), factory.createPolygon( factory.createLinearRing(randomCoordinateRing(89)), new LinearRing[]{factory.createLinearRing(randomCoordinateRing(112)), factory.createLinearRing(randomCoordinateRing(4)), factory.createLinearRing(randomCoordinateRing(43))})})); }
Example #6
Source File: TWKBReader.java From geowave with Apache License 2.0 | 6 votes |
private Polygon readPolygon( final PrecisionReader precision, final byte metadata, final ByteBuffer input) throws IOException { if ((metadata & TWKBUtils.EMPTY_GEOMETRY) != 0) { return GeometryUtils.GEOMETRY_FACTORY.createPolygon(); } final int numRings = VarintUtils.readUnsignedInt(input); final LinearRing exteriorRing = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(precision.readPointArray(input)); final LinearRing[] interiorRings = new LinearRing[numRings - 1]; for (int i = 0; i < (numRings - 1); i++) { interiorRings[i] = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(precision.readPointArray(input)); } return GeometryUtils.GEOMETRY_FACTORY.createPolygon(exteriorRing, interiorRings); }
Example #7
Source File: RasterizedSpatialiteLasLayer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private static void drawLevels( ASpatialDb db, ColorInterpolator colorInterp, PointTransformation pointTransformation, Geometry polygon, Graphics2D gr, int lasLevelsNum, MathTransform data2NwwTransform, boolean doIntensity, int finalTileSize ) throws Exception { int maxPerImage = 100000; List<LasLevel> lasLevels = LasLevelsTable.getLasLevels(db, lasLevelsNum, polygon); int size = lasLevels.size(); if (size > 0) { int jump = size / maxPerImage; for( int i = 0; i < size; i = i + 1 + jump ) { LasLevel lasLevel = lasLevels.get(i); Polygon levelPolygon = lasLevel.polygon; Geometry polygonNww = JTS.transform(levelPolygon, data2NwwTransform); GeneralPath p = polygonToPath(pointTransformation, polygonNww, finalTileSize); Color c = colorInterp.getColorFor(doIntensity ? lasLevel.avgIntensity : lasLevel.avgElev); gr.setPaint(c); gr.fill(p); } } }
Example #8
Source File: GeometryUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Creates simple arrow polygons in the direction of the coordinates. * * @param geometries the geometries (lines and polygons) for which to create the arrows. * @return the list of polygon arrows. */ public static List<Polygon> createSimpleDirectionArrow( Geometry... geometries ) { List<Polygon> polygons = new ArrayList<>(); for( Geometry geometry : geometries ) { for( int i = 0; i < geometry.getNumGeometries(); i++ ) { Geometry geometryN = geometry.getGeometryN(i); if (geometryN instanceof LineString) { LineString line = (LineString) geometryN; polygons.addAll(makeArrows(line)); } else if (geometryN instanceof Polygon) { Polygon polygonGeom = (Polygon) geometryN; LineString exteriorRing = polygonGeom.getExteriorRing(); polygons.addAll(makeArrows(exteriorRing)); int numInteriorRing = polygonGeom.getNumInteriorRing(); for( int j = 0; j < numInteriorRing; j++ ) { LineString interiorRingN = polygonGeom.getInteriorRingN(j); polygons.addAll(makeArrows(interiorRingN)); } } } } return polygons; }
Example #9
Source File: Stanag4676Utils.java From geowave with Apache License 2.0 | 6 votes |
public static SimpleFeatureType createMissionFrameDataType() { final SimpleFeatureTypeBuilder simpleFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); simpleFeatureTypeBuilder.setName(MISSION_FRAME); simpleFeatureTypeBuilder.setNamespaceURI(NAMESPACE); final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder(); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Polygon.class).buildDescriptor("geometry")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).buildDescriptor("Mission")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Date.class).buildDescriptor("TimeStamp")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Integer.class).buildDescriptor("FrameNumber")); final TimeDescriptorConfiguration timeConfig = new TimeDescriptorConfiguration(); timeConfig.setTimeName("TimeStamp"); final SimpleFeatureType type = simpleFeatureTypeBuilder.buildFeatureType(); timeConfig.updateType(type); return type; }
Example #10
Source File: GeometryUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public static Geometry createPolygonsFromRanges( double[] xRanges, double[] yRanges ) { List<Geometry> geomsList = new ArrayList<>(); int cols = xRanges.length - 1; int rows = yRanges.length - 1; for( int x = 0; x < cols - 1; x++ ) { double x1 = xRanges[x]; double x2 = xRanges[x + 1]; for( int y = 0; y < rows - 1; y++ ) { double y1 = xRanges[y]; double y2 = xRanges[y + 1]; Envelope env = new Envelope(x1, x2, y1, y2); Polygon poly = GeometryUtilities.createPolygonFromEnvelope(env); geomsList.add(poly); } } Geometry union = CascadedPolygonUnion.union(geomsList); return union; }
Example #11
Source File: OmsLasConverter.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private void createBboxGeometry( CoordinateReferenceSystem crs, File lasFile, SimpleFeatureCollection outGeodata ) throws Exception { final ReferencedEnvelope3D envelope = lasReader.getHeader().getDataEnvelope(); ReferencedEnvelope env2d = new ReferencedEnvelope(envelope); final Polygon polygon = FeatureUtilities.envelopeToPolygon(new Envelope2D(env2d)); final SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("lasdataenvelope"); b.setCRS(crs); b.add("the_geom", Polygon.class); b.add("id", String.class); final SimpleFeatureType type = b.buildFeatureType(); final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); final Object[] values = new Object[]{polygon, lasFile.getName()}; builder.addAll(values); final SimpleFeature feature = builder.buildFeature(null); ((DefaultFeatureCollection) outGeodata).add(feature); OmsVectorWriter.writeVector(outFile, outGeodata); }
Example #12
Source File: PostgisDb.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@Override public String getSpatialindexBBoxWherePiece( String tableName, String alias, double x1, double y1, double x2, double y2 ) throws Exception { Polygon bounds = DbsUtilities.createPolygonFromBounds(x1, y1, x2, y2); GeometryColumn gCol = getGeometryColumnsForTable(tableName); int srid = gCol.srid; if (alias == null) { alias = ""; } else { alias = alias + "."; } String sql = alias + gCol.geometryColumnName + " && ST_GeomFromText('" + bounds.toText() + "', " + srid + ") AND ST_Intersects(" + alias + gCol.geometryColumnName + ",ST_GeomFromText('" + bounds.toText() + "'," + srid + "))"; return sql; }
Example #13
Source File: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Create a {@link Polygon} from an {@link Envelope}. * * @param envelope the envelope to convert. * @return the created polygon. */ public static Polygon envelopeToPolygon( Envelope envelope ) { double w = envelope.getMinX(); double e = envelope.getMaxX(); double s = envelope.getMinY(); double n = envelope.getMaxY(); Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(w, n); coords[1] = new Coordinate(e, n); coords[2] = new Coordinate(e, s); coords[3] = new Coordinate(w, s); coords[4] = new Coordinate(w, n); GeometryFactory gf = GeometryUtilities.gf(); LinearRing linearRing = gf.createLinearRing(coords); Polygon polygon = gf.createPolygon(linearRing, null); return polygon; }
Example #14
Source File: ShapeConverter.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override public Object parse(String text) throws ConversionException { try { Geometry geometry = new WKTReader(geometryFactory).read(text); if (geometry instanceof LineString) { LineString lineString = (LineString) geometry; // todo return null; } else if (geometry instanceof Polygon) { Polygon polygon = (Polygon) geometry; // todo return null; } else { throw new ConversionException("Failed to parse shape geometry WKT."); } } catch (ParseException e) { throw new ConversionException("Failed to parse shape geometry WKT.", e); } }
Example #15
Source File: SimpleFeatureShapeFigureTest.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private Polygon createPolygon() { return gf.createPolygon(gf.createLinearRing(new Coordinate[]{ new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(0, 1), new Coordinate(0, 0), }), null); }
Example #16
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testOverlapsFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Polygon ls = gf.createPolygon(sf.create( new double[] { 5.5, 6, 7, 6, 7, 7, 5.5, 7, 5.5, 6 }, 2)); Overlaps f = ff.overlaps(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.13"); }
Example #17
Source File: GeoJSONUtils.java From crate with Apache License 2.0 | 5 votes |
private double[][][][] extract(MultiPolygon multiPolygon) { int size = multiPolygon.getNumGeometries(); double[][][][] polygons = new double[size][][][]; for (int i = 0; i < size; i++) { polygons[i] = extract((Polygon) multiPolygon.getGeometryN(i)); } return polygons; }
Example #18
Source File: PolygonAdapter.java From geofence with GNU General Public License v2.0 | 5 votes |
@Override public Polygon unmarshal(String val) throws ParseException { WKTReader wktReader = new WKTReader(); Geometry the_geom = wktReader.read(val); if (the_geom instanceof Polygon) { if (the_geom.getSRID() == 0) the_geom.setSRID(4326); return (Polygon) the_geom; } throw new ParseException("WKB val is not a Polygon."); }
Example #19
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testEqualFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Polygon ls = gf.createPolygon(sf.create(new double[] { 3, 2, 6, 2, 6, 7, 3, 7, 3, 2 }, 2)); Equals f = ff.equal(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.13"); }
Example #20
Source File: OmsExtractBasin.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private void extractVectorBasin() throws Exception { if (!doVector) { return; } Map<String, Object> params = new HashMap<String, Object>(); params.put("outsideValues", Arrays.asList(HMConstants.doubleNovalue)); Collection<Polygon> polygons = FeatureUtilities.doVectorize(outBasin, params); Polygon rightPolygon = null; double maxArea = Double.NEGATIVE_INFINITY; for( Polygon polygon : polygons ) { double area = polygon.getArea(); if (area > maxArea) { rightPolygon = polygon; maxArea = area; } } rightPolygon = smoothVectorBasin(rightPolygon); outVectorBasin = new DefaultFeatureCollection(); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("basins"); b.setCRS(crs); b.add("the_geom", Polygon.class); b.add("area", Double.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Object[] values = new Object[]{rightPolygon, rightPolygon.getArea()}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); ((DefaultFeatureCollection) outVectorBasin).add(feature); }
Example #21
Source File: FeatureLayerConfigurationPersistencyTest.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override protected Layer createLayer(LayerType layerType) throws Exception { final PropertySet configuration = layerType.createLayerConfig(null); final URL shapefileUrl = getClass().getResource("bundeslaender.shp"); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_URL, shapefileUrl); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CRS, DefaultGeographicCRS.WGS84); final Coordinate[] coordinates = { new Coordinate(-10, 50), new Coordinate(+10, 50), new Coordinate(+10, 30), new Coordinate(-10, 30), new Coordinate(-10, 50) }; final GeometryFactory geometryFactory = new GeometryFactory(); final LinearRing ring = geometryFactory.createLinearRing(coordinates); final Polygon clipGeometry = geometryFactory.createPolygon(ring, new LinearRing[0]); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY, clipGeometry); configuration.setValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE, createStyle()); FeatureCollection<SimpleFeatureType, SimpleFeature> fc; try { fc = FeatureUtils.createFeatureCollection( shapefileUrl, DefaultGeographicCRS.WGS84, clipGeometry); } catch (IOException e) { throw new IllegalArgumentException(e); } return new FeatureLayer(layerType, fc, configuration); }
Example #22
Source File: HistogramStatistics.java From geowave with Apache License 2.0 | 5 votes |
@Override public void entryIngested(final GridCoverage entry, final GeoWaveRow... geoWaveRows) { /* * Create the operation for the Histogram with a ROI. No subsampling should be applied. */ final Geometry footprint; if (entry instanceof FitToIndexGridCoverage) { footprint = ((FitToIndexGridCoverage) entry).getFootprintWorldGeometry(); if (footprint == null) { return; } } else { // this is a condition that isn't going to be exercised typically in // any code, but at this point we will assume default CRS footprint = RasterUtils.getFootprint(entry, GeoWaveGTRasterFormat.DEFAULT_CRS); } final GridCoverage originalCoverage; Resolution resolution = null; if (entry instanceof FitToIndexGridCoverage) { originalCoverage = ((FitToIndexGridCoverage) entry).getOriginalCoverage(); resolution = ((FitToIndexGridCoverage) entry).getResolution(); } else { originalCoverage = entry; } if (footprint instanceof GeometryCollection) { final GeometryCollection collection = (GeometryCollection) footprint; for (int g = 0; g < collection.getNumGeometries(); g++) { final Geometry geom = collection.getGeometryN(g); if (geom instanceof Polygon) { mergePoly(originalCoverage, (Polygon) geom, resolution); } } } else if (footprint instanceof Polygon) { mergePoly(originalCoverage, (Polygon) footprint, resolution); } }
Example #23
Source File: LasOverviewCreator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@Execute public void process() throws Exception { checkNull(inLas, outOverview); File[] lasFiles = null; File inLasFile = new File(inLas); if (inLasFile.isDirectory()) { lasFiles = inLasFile.listFiles(new FilenameFilter(){ public boolean accept( File dir, String name ) { return name.toLowerCase().endsWith(".las"); } }); } else { lasFiles = new File[]{inLasFile}; } CoordinateReferenceSystem crs = null; pm.beginTask("Creating overviews...", lasFiles.length); List<Polygon> overviewPolygons = new ArrayList<>(); for( File file : lasFiles ) { try (ALasReader lasReader = ALasReader.getReader(file, null)) { lasReader.open(); ILasHeader header = lasReader.getHeader(); if (crs == null) crs = header.getCrs(); ReferencedEnvelope3D dataEnvelope = header.getDataEnvelope(); Polygon polygon = FeatureUtilities.envelopeToPolygon(dataEnvelope); polygon.setUserData(file.getName()); overviewPolygons.add(polygon); } pm.worked(1); } pm.done(); SimpleFeatureCollection overviewFC = FeatureUtilities.featureCollectionFromGeometry(crs, overviewPolygons.toArray(GeometryUtilities.TYPE_POLYGON)); dumpVector(overviewFC, outOverview); }
Example #24
Source File: RandomGeometryBuilder.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
public MultiPolygon createRandomMultiPolygon() { Polygon[] polygons = new Polygon[numGeometries]; for (int i=0; i<numGeometries; i++) { polygons[i] = createRandomPolygon(); } return geometryFactory.createMultiPolygon(polygons); }
Example #25
Source File: GeometryTranslator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Builds a polygon feature from a dwg solid. * */ public SimpleFeature convertDwgSolid( String typeName, String layerName, DwgSolid solid, int id ) { double[] p1 = solid.getCorner1(); double[] p2 = solid.getCorner2(); double[] p3 = solid.getCorner3(); double[] p4 = solid.getCorner4(); Point2D[] ptos = new Point2D[]{new Point2D.Double(p1[0], p1[1]), new Point2D.Double(p2[0], p2[1]), new Point2D.Double(p3[0], p3[1]), new Point2D.Double(p4[0], p4[1])}; CoordinateList coordList = new CoordinateList(); for( int j = 0; j < ptos.length; j++ ) { Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY()); coordList.add(coord); } coordList.closeRing(); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(typeName); b.setCRS(crs); b.add(THE_GEOM, Polygon.class); b.add(LAYER, String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); LinearRing linearRing = gF.createLinearRing(coordList.toCoordinateArray()); Geometry polygon = gF.createPolygon(linearRing, null); Object[] values = new Object[]{polygon, layerName}; builder.addAll(values); return builder.buildFeature(typeName + "." + id); }
Example #26
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Creates a Geometry class for the given dimensionality. * * @param dimensionality */ private Class<?> getGeometryForDimensionality(int dimensionality) { if (dimensionality == 1) { return Point.class; } if (dimensionality == 2) { return LineString.class; } return Polygon.class; }
Example #27
Source File: GeometryUtil.java From appinventor-extensions with Apache License 2.0 | 5 votes |
public static Polygon ringToPolygon(List<GeoPoint> ring, List<List<GeoPoint>> holes) { LinearRing shell = geoPointsToLinearRing(ring); LinearRing[] holeRings = new LinearRing[holes.size()]; int i = 0; for (List<GeoPoint> h : holes) { holeRings[i++] = geoPointsToLinearRing(h); } return FACTORY.createPolygon(shell, holeRings); }
Example #28
Source File: VectorTileEncoderTest.java From java-vector-tile with Apache License 2.0 | 5 votes |
public void testCWPolygon() { // Exterior ring in clockwise order. List<Coordinate> cs = new ArrayList<Coordinate>(); cs.add(new Coordinate(3, 6)); cs.add(new Coordinate(20, 34)); cs.add(new Coordinate(8, 12)); cs.add(new Coordinate(3, 6)); Coordinate[] coordinates = cs.toArray(new Coordinate[cs.size()]); assertFalse(Orientation.isCCW(coordinates)); Polygon polygon = gf.createPolygon(coordinates); List<Integer> commands = new VectorTileEncoder(256).commands(polygon); assertNotNull(commands); assertCommand(9, commands, 0); assertCommand(6, commands, 1); assertCommand(12, commands, 2); assertCommand(18, commands, 3); assertCommand(10, commands, 4); assertCommand(12, commands, 5); assertCommand(24, commands, 6); assertCommand(44, commands, 7); assertCommand(15, commands, 8); assertEquals(9, commands.size()); }
Example #29
Source File: ODataFesParserTest.java From arctic-sea with Apache License 2.0 | 5 votes |
@Test public void testSamplingGeometryGeoIntersectsPolygon() throws Exception { Filter<?> filter = parser.decode(String.format("geo.intersects(samplingGeometry,geometry'SRID=%s;%s')", polygon.getSRID(), wktGeometry)); assertThat(filter, is(instanceOf(SpatialFilter.class))); SpatialFilter sf = (SpatialFilter) filter; assertThat(sf.getSrid(), is(4326)); assertThat(sf.getGeometry().isEnvelope(), is(false)); assertThat(sf.getGeometry().isGeometry(), is(true)); assertThat(sf.getGeometry().getGeometry().get(), is(instanceOf(Polygon.class))); assertThat(sf.getValueReference(), is("http://www.opengis.net/req/omxml/2.0/data/samplingGeometry")); }
Example #30
Source File: VectorTileEncoderTest.java From java-vector-tile with Apache License 2.0 | 5 votes |
public void testPolygonCommands() { // https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md // Ex.: MoveTo(3, 6), LineTo(8, 12), LineTo(20, 34), ClosePath List<Coordinate> cs = new ArrayList<Coordinate>(); cs.add(new Coordinate(3, 6)); cs.add(new Coordinate(8, 12)); cs.add(new Coordinate(20, 34)); cs.add(new Coordinate(3, 6)); Polygon polygon = gf.createPolygon(cs.toArray(new Coordinate[cs.size()])); List<Integer> commands = new VectorTileEncoder(256).commands(polygon); assertNotNull(commands); // Encoded as: [ 9 6 12 18 10 12 24 44 15 ] assertCommand(9, commands, 0); assertCommand(6, commands, 1); assertCommand(12, commands, 2); assertCommand(18, commands, 3); assertCommand(10, commands, 4); assertCommand(12, commands, 5); assertCommand(24, commands, 6); assertCommand(44, commands, 7); assertCommand(15, commands, 8); assertEquals(9, commands.size()); }