org.locationtech.jts.geom.Geometry.getFactory()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(210)

本文整理了Java中org.locationtech.jts.geom.Geometry.getFactory()方法的一些代码示例,展示了Geometry.getFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.getFactory()方法的具体详情如下:
包路径:org.locationtech.jts.geom.Geometry
类名称:Geometry
方法名:getFactory

Geometry.getFactory介绍

[英]Gets the factory which contains the context in which this geometry was created.
[中]获取包含创建此几何体的上下文的工厂。

代码示例

代码示例来源:origin: geotools/geotools

  1. public GeometryFactory getFactory() {
  2. return geometry.getFactory();
  3. }

代码示例来源:origin: geotools/geotools

  1. private GeometryCollection wrap(Geometry geometry) {
  2. if (geometry instanceof Point) {
  3. return geometry.getFactory().createMultiPoint(new Point[] {(Point) geometry});
  4. } else if (geometry instanceof LineString) {
  5. return geometry.getFactory()
  6. .createMultiLineString(new LineString[] {(LineString) geometry});
  7. } else if (geometry instanceof Polygon) {
  8. return geometry.getFactory().createMultiPolygon(new Polygon[] {(Polygon) geometry});
  9. }
  10. throw new IllegalArgumentException("Unable to create multi geometry from " + geometry);
  11. }
  12. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Tests if a specified {@link Point2D}is inside the boundary of the <code>Shape</code>.
  3. *
  4. * @param p a specified <code>Point2D</code>
  5. * @return <code>true</code> if the specified <code>Point2D</code> is inside the boundary of the
  6. * <code>Shape</code>; <code>false</code> otherwise.
  7. */
  8. public boolean contains(Point2D p) {
  9. Coordinate coord = new Coordinate(p.getX(), p.getY());
  10. Geometry point = geometry.getFactory().createPoint(coord);
  11. return geometry.contains(point);
  12. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Tests if a specified {@link Point2D} is inside the boundary of the <code>Shape</code>.
  3. *
  4. * @param p a specified <code>Point2D</code>
  5. * @return <code>true</code> if the specified <code>Point2D</code> is inside the boundary of the
  6. * <code>Shape</code>; <code>false</code> otherwise.
  7. */
  8. public boolean contains(Point2D p) {
  9. Coordinate coord = new Coordinate(p.getX(), p.getY());
  10. Geometry point = geometry.getFactory().createPoint(coord);
  11. return geometry.contains(point);
  12. }

代码示例来源:origin: geotools/geotools

  1. public static Geometry octagonalEnvelope(Geometry arg0) {
  2. if (arg0 == null) return null;
  3. OctagonalEnvelope env = new OctagonalEnvelope(arg0);
  4. return env.toGeometry(arg0.getFactory());
  5. }

代码示例来源:origin: geotools/geotools

  1. private Geometry adaptGeometry(final Geometry value, Class<? extends Geometry> targetType) {
  2. final Class<? extends Geometry> currentClass = value.getClass();
  3. final GeometryFactory factory = value.getFactory();
  4. Geometry adapted;
  5. if (MultiPoint.class == targetType && Point.class == currentClass) {
  6. adapted = factory.createMultiPoint(value.getCoordinates());
  7. } else if (MultiLineString.class == targetType && LineString.class == currentClass) {
  8. adapted = factory.createMultiLineString(new LineString[] {(LineString) value});
  9. } else if (MultiPolygon.class == targetType && Polygon.class == currentClass) {
  10. adapted = factory.createMultiPolygon(new Polygon[] {(Polygon) value});
  11. } else {
  12. throw new IllegalArgumentException(
  13. "Don't know how to adapt "
  14. + currentClass.getName()
  15. + " to "
  16. + targetType.getName());
  17. }
  18. return adapted;
  19. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Return L as defined by SDO_GTYPE (either 3,4 or 0).
  3. *
  4. * <p>L represents support for LRS (Liniar Referencing System?). JTS Geometry objects do not
  5. * support LRS so this will be 0.
  6. *
  7. * <p>Subclasses may override as required.
  8. *
  9. * @param geom
  10. * @return <code>0</code>
  11. */
  12. public static int L(Geometry geom) {
  13. CoordinateSequenceFactory f = geom.getFactory().getCoordinateSequenceFactory();
  14. if (f instanceof CoordinateAccessFactory) {
  15. return ((CoordinateAccessFactory) f).getDimension();
  16. } else {
  17. return 0;
  18. }
  19. }

代码示例来源:origin: geotools/geotools

  1. @Override
  2. protected void visitLiteralGeometry(Literal expression) throws IOException {
  3. Geometry g = (Geometry) evaluateLiteral(expression, Geometry.class);
  4. if (g instanceof LinearRing) {
  5. // WKT does not support linear rings
  6. g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence());
  7. }
  8. out.write("ST_GeomFromText('" + g.toText() + "', " + currentSRID + ")");
  9. }

代码示例来源:origin: geotools/geotools

  1. @Override
  2. protected void visitLiteralGeometry(Literal expression) throws IOException {
  3. Geometry g = (Geometry) evaluateLiteral(expression, Geometry.class);
  4. if (g instanceof LinearRing) {
  5. // WKT does not support linear rings
  6. g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence());
  7. }
  8. out.write("geometry::STGeomFromText('" + g.toText() + "', " + currentSRID + ")");
  9. }

代码示例来源:origin: geotools/geotools

  1. @Override
  2. protected void visitLiteralGeometry(Literal expression) throws IOException {
  3. Geometry g = (Geometry) evaluateLiteral(expression, Geometry.class);
  4. if (g instanceof LinearRing) {
  5. // WKT does not support linear rings
  6. g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence());
  7. }
  8. out.write("GeomFromText('" + g.toText() + "', " + currentSRID + ")");
  9. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Tests if the specified coordinates are inside the boundary of the <code>Shape</code>.
  3. *
  4. * @param x the specified coordinates, x value
  5. * @param y the specified coordinates, y value
  6. * @return <code>true</code> if the specified coordinates are inside the <code>Shape</code>
  7. * boundary; <code>false</code> otherwise.
  8. */
  9. public boolean contains(double x, double y) {
  10. Coordinate coord = new Coordinate(x, y);
  11. Geometry point = geometry.getFactory().createPoint(coord);
  12. return geometry.contains(point);
  13. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Tests if the specified coordinates are inside the boundary of the <code>Shape</code>.
  3. *
  4. * @param x the specified coordinates, x value
  5. * @param y the specified coordinates, y value
  6. * @return <code>true</code> if the specified coordinates are inside the <code>Shape</code>
  7. * boundary; <code>false</code> otherwise.
  8. */
  9. public boolean contains(double x, double y) {
  10. Coordinate coord = new Coordinate(x, y);
  11. Geometry point = geometry.getFactory().createPoint(coord);
  12. return geometry.contains(point);
  13. }

代码示例来源:origin: geotools/geotools

  1. @Override
  2. public void setGeometryValue(
  3. Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column)
  4. throws SQLException {
  5. if (g != null && !g.isEmpty()) {
  6. if (g instanceof LinearRing) {
  7. // postgis does not handle linear rings, convert to just a line string
  8. g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence());
  9. }
  10. byte[] bytes = new WKBWriter(dimension).write(g);
  11. ps.setBytes(column, bytes);
  12. } else {
  13. ps.setNull(column, Types.OTHER, "Geometry");
  14. }
  15. }

代码示例来源:origin: geotools/geotools

  1. @Override
  2. public void encodeGeometryValue(Geometry value, int dimension, int srid, StringBuffer sql)
  3. throws IOException {
  4. if (value == null || value.isEmpty()) {
  5. sql.append("NULL");
  6. } else {
  7. if (value instanceof LinearRing && !(value instanceof CurvedRing)) {
  8. // postgis does not handle linear rings, convert to just a line string
  9. value =
  10. value.getFactory()
  11. .createLineString(((LinearRing) value).getCoordinateSequence());
  12. }
  13. WKTWriter writer = new WKTWriter2(dimension);
  14. String wkt = writer.write(value);
  15. sql.append("ST_GeomFromText('" + wkt + "', " + srid + ")");
  16. }
  17. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Creates a jts Geometry object representing a rectangle with the given parameters
  3. *
  4. * @param x left coordinate
  5. * @param y bottom coordinate
  6. * @param w width
  7. * @param h height
  8. * @return a rectangle with the specified position and size
  9. */
  10. private Geometry createRectangle(double x, double y, double w, double h) {
  11. Coordinate[] coords = {
  12. new Coordinate(x, y), new Coordinate(x, y + h),
  13. new Coordinate(x + w, y + h), new Coordinate(x + w, y),
  14. new Coordinate(x, y)
  15. };
  16. LinearRing lr = geometry.getFactory().createLinearRing(coords);
  17. return geometry.getFactory().createPolygon(lr, null);
  18. }

代码示例来源:origin: geotools/geotools

  1. boolean hasSameValuesAndStructure(Geometry g1, Geometry g2) {
  2. if (!g1.equalsExact(g2, ORD_TOLERANCE)) return false;
  3. if (g1.getFactory() != g2.getFactory()) return false;
  4. CoordinateSequence seq = CoordinateSequenceFinder.find(g1);
  5. if (!CoordinateSequenceSchemaChecker.check(g2, seq.getClass(), seq.getDimension()))
  6. return false;
  7. return true;
  8. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Extracts a {@link CurvedGeometryFactory} from the provided geometry, either by just returning
  3. * the one that is held by the geometry, if consistent with its tolerance, or by creating a new
  4. * one
  5. *
  6. * @param curved
  7. * @return
  8. */
  9. public static CurvedGeometryFactory getFactory(CurvedGeometry<?> curved) {
  10. GeometryFactory factory = ((Geometry) curved).getFactory();
  11. if (factory instanceof CurvedGeometryFactory) {
  12. CurvedGeometryFactory cf = (CurvedGeometryFactory) factory;
  13. if (cf.getTolerance() == curved.getTolerance()) {
  14. return cf;
  15. }
  16. }
  17. return new CurvedGeometryFactory(factory, curved.getTolerance());
  18. }
  19. }

代码示例来源:origin: geotools/geotools

  1. public Object visit(Literal expression, Object extraData) {
  2. if (!(expression.getValue() instanceof Geometry)) return super.visit(expression, extraData);
  3. // check if reprojection is needed
  4. Geometry geom = (Geometry) expression.getValue();
  5. if (geom.getUserData() != null && geom.getUserData() instanceof CoordinateReferenceSystem)
  6. return super.visit(expression, extraData);
  7. // clone the geometry and assign the new crs
  8. Geometry clone = geom.getFactory().createGeometry(geom);
  9. clone.setUserData(defaultCrs);
  10. // clone
  11. return ff.literal(clone);
  12. }
  13. }

代码示例来源:origin: geotools/geotools

  1. @DescribeProcess(
  2. title = "Polygonize",
  3. description =
  4. "Creates a set of polygons from linestrings delineating them. The linestrings must be correctly noded (i.e. touch only at endpoints)."
  5. )
  6. @DescribeResult(description = "The collection of created polygons")
  7. public static Geometry polygonize(
  8. @DescribeParameter(name = "geom", description = "Linework to polygonize")
  9. Geometry geom) {
  10. @SuppressWarnings("rawtypes")
  11. List lines = LineStringExtracter.getLines(geom);
  12. Polygonizer polygonizer = new Polygonizer();
  13. polygonizer.add(lines);
  14. @SuppressWarnings("rawtypes")
  15. Collection polys = polygonizer.getPolygons();
  16. Polygon[] polyArray = GeometryFactory.toPolygonArray(polys);
  17. return geom.getFactory().createGeometryCollection(polyArray);
  18. }

代码示例来源:origin: geotools/geotools

  1. public void testGeometryFactoryHint() throws Exception {
  2. FilterFactory ff = dataStore.getFilterFactory();
  3. PropertyIsEqualTo filter =
  4. ff.equals(ff.property(aname("stringProperty")), ff.literal("one"));
  5. Query query = new Query();
  6. query.setFilter(filter);
  7. // check we're respecting the geometry factory hint
  8. GeometryFactory gf1 = new GeometryFactory();
  9. query.setHints(new Hints(Hints.JTS_GEOMETRY_FACTORY, gf1));
  10. SimpleFeature f1 = DataUtilities.first(featureSource.getFeatures(query));
  11. assertSame(gf1, ((Geometry) f1.getDefaultGeometry()).getFactory());
  12. // check we're respecting the geometry factory when changing it
  13. GeometryFactory gf2 = new GeometryFactory();
  14. query.setHints(new Hints(Hints.JTS_GEOMETRY_FACTORY, gf2));
  15. SimpleFeature f2 = DataUtilities.first(featureSource.getFeatures(query));
  16. assertSame(gf2, ((Geometry) f2.getDefaultGeometry()).getFactory());
  17. }

相关文章