private Geometry fixPolygonalTopology(Geometry geom) { /** * If precision model was *not* changed, need to flip * geometry to targetPM, buffer in that model, then flip back */ Geometry geomToBuffer = geom; if (! changePrecisionModel) { geomToBuffer = changePM(geom, targetPM); } Geometry bufGeom = geomToBuffer.buffer(0); Geometry finalGeom = bufGeom; if (! changePrecisionModel) { // a slick way to copy the geometry with the original precision factory finalGeom = geom.getFactory().createGeometry(bufGeom); } return finalGeom; }
public void execute(SplitPolygonRequest request, SplitPolygonResponse response) throws Exception { // convert to most accurate precision model Polygon polygon = null; try { polygon = (Polygon) converter.toJts(request.getPolygon()); } catch (Exception e) { // throw new GeomajasException(); } GeometryFactory factory = new GeometryFactory(new PrecisionModel(), polygon.getFactory().getSRID()); Polygon p = (Polygon) factory.createGeometry(polygon); LineString l = (LineString) factory.createGeometry(converter.toJts(request.getLineString())); int precision = 11; com.vividsolutions.jts.geom.Geometry buffered = factory.createGeometryCollection(null); while (buffered.isEmpty()) { buffered = l.buffer(Math.pow(10.0, -(precision--))); } com.vividsolutions.jts.geom.Geometry diff = p.difference(buffered); if (diff instanceof Polygon) { response.setPolygons(new Geometry[] {converter.toDto(diff)}); } else if (diff instanceof MultiPolygon) { Geometry[] polygons = new Geometry[diff.getNumGeometries()]; for (int i = 0; i < diff.getNumGeometries(); i++) { polygons[i] = converter.toDto(diff.getGeometryN(i)); // makePrecise(polygon.getPrecisionModel(), polygons[i]); } response.setPolygons(polygons); } }
public Geometry createGeometry(final Geometry _g) { return super.createGeometry(_g); } /**
@Override public Optional<Geometry> get(int index, GeometryFactory gf) { Geometry g = (Geometry) values.get(index); Geometry g2 = null; if (g != null) { g2 = gf.createGeometry(g); } return Optional.fromNullable(g2); }
/** * Sets the geometry contained in this lite shape. Convenient to reuse this * object instead of creating it again and again during rendering * * @param g * @throws TransformException * @throws FactoryException */ public void setGeometry(Geometry g) throws TransformException, FactoryException { if (g != null) { this.geometry = getGeometryFactory().createGeometry(g); transformGeometry(geometry); } }
/** * Sets the geometry contained in this lite shape. Convenient to reuse this * object instead of creating it again and again during rendering * * @param g * @throws TransformException * @throws FactoryException */ public void setGeometry(Geometry g) throws TransformException, FactoryException { if (g != null) { this.geometry = getGeometryFactory().createGeometry(g); transformGeometry(geometry); } }
private Geometry fixPolygonalTopology(Geometry geom) { /** * If precision model was *not* changed, need to flip * geometry to targetPM, buffer in that model, then flip back */ Geometry geomToBuffer = geom; if (! changePrecisionModel) { geomToBuffer = changePM(geom, targetPM); } Geometry bufGeom = geomToBuffer.buffer(0); Geometry finalGeom = bufGeom; if (! changePrecisionModel) { // a slick way to copy the geometry with the original precision factory finalGeom = geom.getFactory().createGeometry(bufGeom); } return finalGeom; }
g = factory.createGeometry(g);
@Nullable private TopoGeom createObject(String featureId, Geometry geom, Map<String, Object> properties) throws MismatchedDimensionException, TransformException { // // snap to pixel geom = fixedGeometryFactory.createGeometry(geom); if (geom.isEmpty()) { return null; } if (geom instanceof GeometryCollection && geom.getNumGeometries() == 1) { geom = geom.getGeometryN(0); } TopoGeom geometry = createGeometry(geom); geometry.setProperties(properties); geometry.setId(featureId); return geometry; }
if (useFixedPrecision){ geomFactory = PRECISE_FACTORY; cloned = geomFactory.createGeometry(geom); Coordinate[] coords = cloned.getCoordinates(); for (Coordinate coord : coords) {
/** * Creates a new LiteShape object. * * @param geom - the wrapped geometry * @param at - the transformation applied to the geometry in order to get to the shape points * @param generalize - set to true if the geometry need to be generalized * during rendering * */ public LiteShape(Geometry geom, AffineTransform at, boolean generalize) { if( geom!=null) this.geometry =getGeometryFactory().createGeometry(geom); this.affineTransform = at; this.generalize = generalize; if (at==null){ yScale=xScale=1; return; } xScale = (float) Math.sqrt( (at.getScaleX() * at.getScaleX()) + (at.getShearX() * at.getShearX())); yScale = (float) Math.sqrt( (at.getScaleY() * at.getScaleY()) + (at.getShearY() * at.getShearY())); }
/** * Creates a new LiteShape object. * * @param geom - the wrapped geometry * @param at - the transformation applied to the geometry in order to get to the shape points * @param generalize - set to true if the geometry need to be generalized * during rendering * */ public LiteShape(Geometry geom, AffineTransform at, boolean generalize) { if( geom!=null) this.geometry =getGeometryFactory().createGeometry(geom); this.affineTransform = at; this.generalize = generalize; if (at==null){ yScale=xScale=1; return; } xScale = (float) Math.sqrt( (at.getScaleX() * at.getScaleX()) + (at.getShearX() * at.getShearX())); yScale = (float) Math.sqrt( (at.getScaleY() * at.getScaleY()) + (at.getShearY() * at.getShearY())); }
public Object visit(Literal expression, Object extraData) { if (!(expression.getValue() instanceof Geometry)) return super.visit(expression, extraData); // check if reprojection is needed Geometry geom = (Geometry) expression.getValue(); if(geom.getUserData() != null && geom.getUserData() instanceof CoordinateReferenceSystem) return super.visit(expression, extraData); // clone the geometry and assign the new crs Geometry clone = geom.getFactory().createGeometry(geom); clone.setUserData(defaultCrs); // clone return ff.literal(clone); } }
/** * Returns a new ROI created by applying the given transform to * this ROI. * * @param at the transform * * @return the new ROI */ @Override public ROI transform(AffineTransform at) { Geometry cloned = (Geometry) theGeom.getGeometry().clone(); cloned.apply(new AffineTransformation(at.getScaleX(), at.getShearX(), at.getTranslateX(), at.getShearY(), at.getScaleY(), at.getTranslateY())); if (useFixedPrecision){ Geometry fixed = PRECISE_FACTORY.createGeometry(cloned); Coordinate[] coords = fixed.getCoordinates(); for (Coordinate coord : coords) { Coordinate precise = coord; PRECISION.makePrecise(precise); } cloned = fixed; } return new ROIGeometry(cloned); }