Java Code Examples for com.vividsolutions.jts.geom.Geometry#getNumPoints()
The following examples show how to use
com.vividsolutions.jts.geom.Geometry#getNumPoints() .
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: NominatimGeocoder.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
/** * Returns a simplified version of the input geometry with a number of * points reduced to a maximum provided in parameter. * * The simplification algorithm can be outlined as follow: * <ul> * <li>returns null if the input geometry is null;</li> * <li>returns the input geometry if the input one has already a number * of points lower or equal to the maximum allowed;</li> * <li></li> * </ul> * * @param input_geometry the geometry to be simplified. * @param max_output_points the maximum number of points of output * geometry. * * @return the simplified geometry or null if the input is null. */ private static Geometry simplifyGeometry(final Geometry input_geometry, final int max_output_points) { Geometry geometry = input_geometry; double cluster_factor = 0.2; int current_point_number = -1; int previous_point_number = -2; while ((current_point_number != previous_point_number) && (geometry.getNumPoints() > max_output_points)) { previous_point_number = current_point_number; current_point_number = geometry.getNumPoints(); geometry = simplifyGeometry(geometry, max_output_points, cluster_factor); cluster_factor += 0.05; } return geometry; }
Example 2
Source File: GeoTemporalMongoDBStorageStrategy.java From rya with Apache License 2.0 | 6 votes |
@Override public Document serialize(final RyaStatement ryaStatement) { final Document doc = new Document("_id", ryaStatement.getSubject().hashCode()); final IRI obj = ryaStatement.getObject().getDataType(); if(obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) { try { final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser()); if (geo.getNumPoints() > 1) { doc.append(GEO_KEY, geoStrategy.getCorrespondingPoints(geo)); } else { doc.append(GEO_KEY, geoStrategy.getDBPoint(geo)); } } catch (final ParseException e) { LOG.error("Could not create geometry for statement " + ryaStatement, e); return null; } } else { doc.append(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData())); } return doc; }
Example 3
Source File: GeoMongoDBStorageStrategy.java From rya with Apache License 2.0 | 6 votes |
@Override public Document serialize(final RyaStatement ryaStatement) { // if the object is wkt, then try to index it // write the statement data to the fields try { final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser()); if(geo == null) { LOG.error("Failed to parse geo statement: " + statement.toString()); return null; } final Document base = super.serialize(ryaStatement); if (geo.getNumPoints() > 1) { base.append(GEO, getCorrespondingPoints(geo)); } else { base.append(GEO, getDBPoint(geo)); } return base; } catch(final ParseException e) { LOG.error("Could not create geometry for statement " + ryaStatement, e); return null; } }
Example 4
Source File: VariableWidthBuffer.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static Geometry bufferAternating(Geometry line, double width1, double width2) { int nPts = line.getNumPoints(); double[] width = new double[nPts]; for (int i = 0; i < width.length; i++) { width[i] = (i % 2) == 0 ? width1 : width2; } VariableWidthBuffer vb = new VariableWidthBuffer(line, width); return vb.getResult(); }
Example 5
Source File: WKTPanel.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public void setText(Geometry g, int geomIndex) { String txt = null; if (g == null) txt = ""; else if (g.getNumPoints() > TestBuilderModel.MAX_DISPLAY_POINTS) txt = GeometryEditModel.toStringVeryLarge(g); else txt = GeometryEditModel.getText(g, GeometryType.WELLKNOWNTEXT); switch (geomIndex) { case 0: aTextArea.setText(txt); break; case 1: bTextArea.setText(txt); break; } }
Example 6
Source File: CGAlgorithmFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static int orientationIndex(Geometry segment, Geometry ptGeom) { if (segment.getNumPoints() != 2 || ptGeom.getNumPoints() != 1) { throw new IllegalArgumentException("A must have two points and B must have one"); } Coordinate[] segPt = segment.getCoordinates(); Coordinate p = ptGeom.getCoordinate(); int index = CGAlgorithms.orientationIndex(segPt[0], segPt[1], p); return index; }
Example 7
Source File: CGAlgorithmFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static int orientationIndexDD(Geometry segment, Geometry ptGeom) { if (segment.getNumPoints() != 2 || ptGeom.getNumPoints() != 1) { throw new IllegalArgumentException("A must have two points and B must have one"); } Coordinate[] segPt = segment.getCoordinates(); Coordinate p = ptGeom.getCoordinate(); int index = CGAlgorithmsDD.orientationIndex(segPt[0], segPt[1], p); return index; }
Example 8
Source File: NominatimGeocoder.java From DataHubSystem with GNU Affero General Public License v3.0 | 4 votes |
private static Geometry simplifyGeometry(final Geometry input_geometry, final int max_output_points, final double cluster_factor) { // Return null if the input geometry is null if (input_geometry == null) { return null; } // Return the input geometry if the number of points is already lower // or equal to the maximum allowed if (input_geometry.getNumPoints() <= max_output_points) { return input_geometry; } // Assign local geometry to refine Geometry geometry = input_geometry; if (geometry.getNumGeometries() > 1) { geometry = convexHullOneLevel(geometry).union(); geometry = clusterizeGeometry(geometry, cluster_factor); } int current_point_number = geometry.getNumPoints(); int previous_point_number = -1; int iteration_count = 0; double tolerance = 0.005; while ((current_point_number > max_output_points) && (iteration_count < 10)) { previous_point_number = current_point_number; current_point_number = geometry.getNumPoints(); if (current_point_number == previous_point_number) { iteration_count += 1; } else { iteration_count = 0; } geometry = TopologyPreservingSimplifier.simplify(geometry, tolerance); tolerance += 0.005; } return geometry; }
Example 9
Source File: ShapeExecuter.java From gama with GNU General Public License v3.0 | 4 votes |
@Override Rectangle2D executeOn(final IScope scope, final IGraphics gr, final DrawingData data) throws GamaRuntimeException { final IShape shape = constantShape == null ? asGeometry(scope, item.value(scope), false) : constantShape; if (shape == null) { return null; } final DrawingAttributes attributes = computeAttributes(scope, data, shape); Geometry gg = shape.getInnerGeometry(); if (gg == null) { return null; } final ICoordinates ic = getContourCoordinates(gg); ic.ensureClockwiseness(); // If the graphics is 2D, we pre-translate and pre-rotate the geometry if (gr.is2D()) { ic.getCenter(center); rotate(gg, center, attributes.getRotation()); final GamaPoint location = attributes.getLocation(); if (location != null) { if (gg.getNumPoints() == 1) { gg = GEOMETRY_FACTORY.createPoint(location); } else { translate(gg, center, location); } } gg.geometryChanged(); } if (hasArrows) { final Geometry withArrows = addArrows(scope, gg, !attributes.isEmpty()); if (withArrows != gg) { gg = withArrows; attributes.setType(IShape.Type.NULL); } } final Geometry withTorus = addToroidalParts(scope, gg); if (withTorus != gg) { gg = withTorus; attributes.setType(IShape.Type.NULL); } // XXX EXPERIMENTAL See Issue #1521 if (GamaPreferences.Displays.DISPLAY_ONLY_VISIBLE.getValue() && !scope.getExperiment().isHeadless()) { final Envelope3D e = shape.getEnvelope(); try { final Envelope visible = gr.getVisibleRegion(); if (visible != null) { if (!visible.intersects(e)) { return null; } // XXX EXPERIMENTAL } } finally { e.dispose(); } } // The textures are computed as well in advance addTextures(scope, attributes); // And we ask the IGraphics object to draw the shape return gr.drawShape(gg, attributes); }