Java Code Examples for com.vividsolutions.jts.geom.Geometry#apply()
The following examples show how to use
com.vividsolutions.jts.geom.Geometry#apply() .
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: FacetSequenceTreeBuilder.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Creates facet sequences * * @param g * @return List<GeometryFacetSequence> */ private static List computeFacetSequences(Geometry g) { final List sections = new ArrayList(); g.apply(new GeometryComponentFilter() { public void filter(Geometry geom) { CoordinateSequence seq = null; if (geom instanceof LineString) { seq = ((LineString) geom).getCoordinateSequence(); addFacetSequences(seq, sections); } else if (geom instanceof Point) { seq = ((Point) geom).getCoordinateSequence(); addFacetSequences(seq, sections); } } }); return sections; }
Example 2
Source File: DivideLineStringTool.java From geowe-core with GNU General Public License v3.0 | 6 votes |
private Collection<Geometry> getLines(final Geometry geom) { final List<Geometry> linesList = new ArrayList<Geometry>(); final LinearComponentExtracter lineFilter = new LinearComponentExtracter( linesList); geom.apply(lineFilter); return linesList; }
Example 3
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 5 votes |
public static void applyToInnerGeometries(final GeometryCollection g, final GeometryFilter f) { final int geoms = g.getNumGeometries(); if (geoms == 0) { return; } for (int i = 0; i < geoms; i++) { final Geometry sub = g.getGeometryN(i); sub.apply(f); } }
Example 4
Source File: AffineTransformationTest.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
void checkTransformation(String geomStr) throws IOException, ParseException, NoninvertibleTransformationException { Geometry geom = rdr.read(geomStr); AffineTransformation trans = AffineTransformation .rotationInstance(Math.PI / 2); AffineTransformation inv = trans.getInverse(); Geometry transGeom = geom.copy(); transGeom.apply(trans); // System.out.println(transGeom); transGeom.apply(inv); // check if transformed geometry is equal to original boolean isEqual = geom.equalsExact(transGeom, 0.0005); assertTrue(isEqual); }
Example 5
Source File: LineDissolver.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Adds a {@link Geometry} to be dissolved. * Any number of geometries may be adde by calling this method multiple times. * Any type of Geometry may be added. The constituent linework will be * extracted to be dissolved. * * @param geometry geometry to be line-merged */ public void add(Geometry geometry) { geometry.apply(new GeometryComponentFilter() { public void filter(Geometry component) { if (component instanceof LineString) { add((LineString)component); } } }); }
Example 6
Source File: LineMerger.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Adds a Geometry to be processed. May be called multiple times. * Any dimension of Geometry may be added; the constituent linework will be * extracted. * * @param geometry geometry to be line-merged */ public void add(Geometry geometry) { geometry.apply(new GeometryComponentFilter() { public void filter(Geometry component) { if (component instanceof LineString) { add((LineString)component); } } }); }
Example 7
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 5 votes |
public static void translate(final Geometry geometry, final double dx, final double dy, final double dz) { geometry.apply((final Coordinate p) -> { p.x += dx; p.y += dy; p.z += dz; }); geometry.geometryChanged(); }
Example 8
Source File: GamaGeoJsonFile.java From gama with GNU General Public License v3.0 | 5 votes |
public void readShapes(final IScope scope) { final IList<IShape> list = getBuffer(); int size = 0; final SimpleFeatureCollection fc = getFeatureCollection(scope); if (fc == null) { return; } final Envelope3D env = Envelope3D.of(fc.getBounds()); size = fc.size(); int index = 0; computeProjection(scope, env); try (SimpleFeatureIterator reader = fc.features()) { while (reader.hasNext()) { index++; if (index % 20 == 0) { scope.getGui().getStatus(scope).setSubStatusCompletion(index / (double) size); } final SimpleFeature feature = reader.next(); Geometry g = (Geometry) feature.getDefaultGeometry(); if (g != null && !g.isEmpty() /* Fix for Issue 725 && 677 */ ) { g = gis.transform(g); if (!with3D) { g.apply(ZERO_Z); g.geometryChanged(); } list.add(new GamaGisGeometry(g, feature)); } else if (g == null) { // See Issue 725 GAMA.reportError(scope, GamaRuntimeException .warning("GamaGeoJsonFile.fillBuffer; geometry could not be added as it is " + "nil: " + feature.getIdentifier(), scope), false); } } } if (size > list.size()) { GAMA.reportError(scope, GamaRuntimeException.warning("Problem with file " + getFile(scope) + ": only " + list.size() + " of the " + size + " geometries could be added", scope), false); } }
Example 9
Source File: SimpleScalingProjection.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public Geometry inverseTransform(Geometry geom) { if (inverseScaling != null) { geom.apply(inverseScaling); geom.geometryChanged(); } return geom; }
Example 10
Source File: MiscellaneousTest2.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public void testUniqueCoordinateArrayFilter() throws Exception { Geometry g = reader.read( "MULTIPOINT(10 10, 20 20, 30 30, 20 20, 10 10)"); UniqueCoordinateArrayFilter f = new UniqueCoordinateArrayFilter(); g.apply(f); assertEquals(3, f.getCoordinates().length); assertEquals(new Coordinate(10, 10), f.getCoordinates()[0]); assertEquals(new Coordinate(20, 20), f.getCoordinates()[1]); assertEquals(new Coordinate(30, 30), f.getCoordinates()[2]); }
Example 11
Source File: WorldProjection.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void inverseConvertUnit(Geometry geom) { if (meterToOtherUnit != null) { geom.apply(meterToOtherUnit); geom.geometryChanged(); } }
Example 12
Source File: WorldProjection.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void convertUnit(Geometry geom) { if (otherUnitToMeter != null) { geom.apply(otherUnitToMeter); geom.geometryChanged(); } }
Example 13
Source File: WorldProjection.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void inverseTranslate(final Geometry geom) { if (absoluteToGisTranslation != null) { geom.apply(absoluteToGisTranslation); geom.geometryChanged(); } }
Example 14
Source File: WorldProjection.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void translate(final Geometry geom) { if (gisToAbsoluteTranslation != null) { geom.apply(gisToAbsoluteTranslation); geom.geometryChanged(); } }
Example 15
Source File: DividePolygonTool.java From geowe-core with GNU General Public License v3.0 | 5 votes |
private Collection<Geometry> getLines(final Geometry geom1, final Geometry geom2) { final List<Geometry> linesList = new ArrayList<Geometry>(); final LinearComponentExtracter lineFilter = new LinearComponentExtracter( linesList); geom1.apply(lineFilter); geom2.apply(lineFilter); return linesList; }
Example 16
Source File: GamaShapeFile.java From gama with GNU General Public License v3.0 | 4 votes |
protected void readShapes(final IScope scope) { scope.getGui().getStatus(scope).beginSubStatus("Reading file " + getName(scope)); ShapefileDataStore store = null; final File file = getFile(scope); final IList list = getBuffer(); int size = 0; try { store = getDataStore(file.toURI().toURL()); final ContentFeatureSource source = store.getFeatureSource(); final Envelope3D env = Envelope3D.of(source.getBounds()); size = source.getCount(Query.ALL); int index = 0; computeProjection(scope, env); try (FeatureReader reader = store.getFeatureReader()) { while (reader.hasNext()) { index++; if (index % 20 == 0) { scope.getGui().getStatus(scope).setSubStatusCompletion(index / (double) size); } final Feature feature = reader.next(); Geometry g = (Geometry) feature.getDefaultGeometryProperty().getValue(); if (g != null && !g.isEmpty() /* Fix for Issue 725 && 677 */ ) { if (!with3D && !g.isValid()) { g = GeometryUtils.cleanGeometry(g); } g = gis.transform(g); if (!with3D) { g.apply(ZERO_Z); g.geometryChanged(); } g = multiPolygonManagement(g); GamaGisGeometry gt = new GamaGisGeometry(g, feature); if (gt.getInnerGeometry() != null) list.add(gt); } else if (g == null) { // See Issue 725 GAMA.reportError(scope, GamaRuntimeException .warning("GamaShapeFile.fillBuffer; geometry could not be added as it is " + "nil: " + feature.getIdentifier(), scope), false); } } } } catch (final IOException e) { throw GamaRuntimeException.create(e, scope); } finally { if (store != null) { store.dispose(); } scope.getGui().getStatus(scope).endSubStatus("Reading file " + getName(scope)); } if (size > list.size()) { GAMA.reportError(scope, GamaRuntimeException.warning("Problem with file " + getFile(scope) + ": only " + list.size() + " of the " + size + " geometries could be added", scope), false); } }
Example 17
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 4 votes |
public static void rotate(final Geometry geometry, final GamaPoint center, final AxisAngle rotation) { if (rotation == null) { return; } final Rotation3D r = new Rotation3D.CenteredOn(rotation, center); geometry.apply(r); geometry.geometryChanged(); }
Example 18
Source File: GeometryCache.java From gama with GNU General Public License v3.0 | 4 votes |
void drawSimpleGeometry(final OpenGL gl, final Geometry geom) throws ExecutionException { geom.apply((GeometryFilter) (g) -> drawer.accept(g)); }
Example 19
Source File: WKBTest.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
private void setZ(Geometry g) { g.apply(new AverageZFilter()); }
Example 20
Source File: Polygonizer.java From jts with GNU Lesser General Public License v2.1 | 2 votes |
/** * Add a {@link Geometry} to the edges to be polygonized. * May be called multiple times. * Any dimension of Geometry may be added; * the constituent linework will be extracted and used * * @param g a {@link Geometry} with linework to be polygonized */ public void add(Geometry g) { g.apply(lineStringAdder); }