本文整理了Java中org.locationtech.jts.geom.Geometry.getFactory()
方法的一些代码示例,展示了Geometry.getFactory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.getFactory()
方法的具体详情如下:
包路径:org.locationtech.jts.geom.Geometry
类名称:Geometry
方法名:getFactory
[英]Gets the factory which contains the context in which this geometry was created.
[中]获取包含创建此几何体的上下文的工厂。
代码示例来源:origin: geotools/geotools
public GeometryFactory getFactory() {
return geometry.getFactory();
}
代码示例来源:origin: geotools/geotools
private GeometryCollection wrap(Geometry geometry) {
if (geometry instanceof Point) {
return geometry.getFactory().createMultiPoint(new Point[] {(Point) geometry});
} else if (geometry instanceof LineString) {
return geometry.getFactory()
.createMultiLineString(new LineString[] {(LineString) geometry});
} else if (geometry instanceof Polygon) {
return geometry.getFactory().createMultiPolygon(new Polygon[] {(Polygon) geometry});
}
throw new IllegalArgumentException("Unable to create multi geometry from " + geometry);
}
}
代码示例来源:origin: geotools/geotools
/**
* Tests if a specified {@link Point2D}is inside the boundary of the <code>Shape</code>.
*
* @param p a specified <code>Point2D</code>
* @return <code>true</code> if the specified <code>Point2D</code> is inside the boundary of the
* <code>Shape</code>; <code>false</code> otherwise.
*/
public boolean contains(Point2D p) {
Coordinate coord = new Coordinate(p.getX(), p.getY());
Geometry point = geometry.getFactory().createPoint(coord);
return geometry.contains(point);
}
代码示例来源:origin: geotools/geotools
/**
* Tests if a specified {@link Point2D} is inside the boundary of the <code>Shape</code>.
*
* @param p a specified <code>Point2D</code>
* @return <code>true</code> if the specified <code>Point2D</code> is inside the boundary of the
* <code>Shape</code>; <code>false</code> otherwise.
*/
public boolean contains(Point2D p) {
Coordinate coord = new Coordinate(p.getX(), p.getY());
Geometry point = geometry.getFactory().createPoint(coord);
return geometry.contains(point);
}
代码示例来源:origin: geotools/geotools
public static Geometry octagonalEnvelope(Geometry arg0) {
if (arg0 == null) return null;
OctagonalEnvelope env = new OctagonalEnvelope(arg0);
return env.toGeometry(arg0.getFactory());
}
代码示例来源:origin: geotools/geotools
private Geometry adaptGeometry(final Geometry value, Class<? extends Geometry> targetType) {
final Class<? extends Geometry> currentClass = value.getClass();
final GeometryFactory factory = value.getFactory();
Geometry adapted;
if (MultiPoint.class == targetType && Point.class == currentClass) {
adapted = factory.createMultiPoint(value.getCoordinates());
} else if (MultiLineString.class == targetType && LineString.class == currentClass) {
adapted = factory.createMultiLineString(new LineString[] {(LineString) value});
} else if (MultiPolygon.class == targetType && Polygon.class == currentClass) {
adapted = factory.createMultiPolygon(new Polygon[] {(Polygon) value});
} else {
throw new IllegalArgumentException(
"Don't know how to adapt "
+ currentClass.getName()
+ " to "
+ targetType.getName());
}
return adapted;
}
代码示例来源:origin: geotools/geotools
/**
* Return L as defined by SDO_GTYPE (either 3,4 or 0).
*
* <p>L represents support for LRS (Liniar Referencing System?). JTS Geometry objects do not
* support LRS so this will be 0.
*
* <p>Subclasses may override as required.
*
* @param geom
* @return <code>0</code>
*/
public static int L(Geometry geom) {
CoordinateSequenceFactory f = geom.getFactory().getCoordinateSequenceFactory();
if (f instanceof CoordinateAccessFactory) {
return ((CoordinateAccessFactory) f).getDimension();
} else {
return 0;
}
}
代码示例来源:origin: geotools/geotools
@Override
protected void visitLiteralGeometry(Literal expression) throws IOException {
Geometry g = (Geometry) evaluateLiteral(expression, Geometry.class);
if (g instanceof LinearRing) {
// WKT does not support linear rings
g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence());
}
out.write("ST_GeomFromText('" + g.toText() + "', " + currentSRID + ")");
}
代码示例来源:origin: geotools/geotools
@Override
protected void visitLiteralGeometry(Literal expression) throws IOException {
Geometry g = (Geometry) evaluateLiteral(expression, Geometry.class);
if (g instanceof LinearRing) {
// WKT does not support linear rings
g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence());
}
out.write("geometry::STGeomFromText('" + g.toText() + "', " + currentSRID + ")");
}
代码示例来源:origin: geotools/geotools
@Override
protected void visitLiteralGeometry(Literal expression) throws IOException {
Geometry g = (Geometry) evaluateLiteral(expression, Geometry.class);
if (g instanceof LinearRing) {
// WKT does not support linear rings
g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence());
}
out.write("GeomFromText('" + g.toText() + "', " + currentSRID + ")");
}
代码示例来源:origin: geotools/geotools
/**
* Tests if the specified coordinates are inside the boundary of the <code>Shape</code>.
*
* @param x the specified coordinates, x value
* @param y the specified coordinates, y value
* @return <code>true</code> if the specified coordinates are inside the <code>Shape</code>
* boundary; <code>false</code> otherwise.
*/
public boolean contains(double x, double y) {
Coordinate coord = new Coordinate(x, y);
Geometry point = geometry.getFactory().createPoint(coord);
return geometry.contains(point);
}
代码示例来源:origin: geotools/geotools
/**
* Tests if the specified coordinates are inside the boundary of the <code>Shape</code>.
*
* @param x the specified coordinates, x value
* @param y the specified coordinates, y value
* @return <code>true</code> if the specified coordinates are inside the <code>Shape</code>
* boundary; <code>false</code> otherwise.
*/
public boolean contains(double x, double y) {
Coordinate coord = new Coordinate(x, y);
Geometry point = geometry.getFactory().createPoint(coord);
return geometry.contains(point);
}
代码示例来源:origin: geotools/geotools
@Override
public void setGeometryValue(
Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column)
throws SQLException {
if (g != null && !g.isEmpty()) {
if (g instanceof LinearRing) {
// postgis does not handle linear rings, convert to just a line string
g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence());
}
byte[] bytes = new WKBWriter(dimension).write(g);
ps.setBytes(column, bytes);
} else {
ps.setNull(column, Types.OTHER, "Geometry");
}
}
代码示例来源:origin: geotools/geotools
@Override
public void encodeGeometryValue(Geometry value, int dimension, int srid, StringBuffer sql)
throws IOException {
if (value == null || value.isEmpty()) {
sql.append("NULL");
} else {
if (value instanceof LinearRing && !(value instanceof CurvedRing)) {
// postgis does not handle linear rings, convert to just a line string
value =
value.getFactory()
.createLineString(((LinearRing) value).getCoordinateSequence());
}
WKTWriter writer = new WKTWriter2(dimension);
String wkt = writer.write(value);
sql.append("ST_GeomFromText('" + wkt + "', " + srid + ")");
}
}
代码示例来源:origin: geotools/geotools
/**
* Creates a jts Geometry object representing a rectangle with the given parameters
*
* @param x left coordinate
* @param y bottom coordinate
* @param w width
* @param h height
* @return a rectangle with the specified position and size
*/
private Geometry createRectangle(double x, double y, double w, double h) {
Coordinate[] coords = {
new Coordinate(x, y), new Coordinate(x, y + h),
new Coordinate(x + w, y + h), new Coordinate(x + w, y),
new Coordinate(x, y)
};
LinearRing lr = geometry.getFactory().createLinearRing(coords);
return geometry.getFactory().createPolygon(lr, null);
}
代码示例来源:origin: geotools/geotools
boolean hasSameValuesAndStructure(Geometry g1, Geometry g2) {
if (!g1.equalsExact(g2, ORD_TOLERANCE)) return false;
if (g1.getFactory() != g2.getFactory()) return false;
CoordinateSequence seq = CoordinateSequenceFinder.find(g1);
if (!CoordinateSequenceSchemaChecker.check(g2, seq.getClass(), seq.getDimension()))
return false;
return true;
}
代码示例来源:origin: geotools/geotools
/**
* Extracts a {@link CurvedGeometryFactory} from the provided geometry, either by just returning
* the one that is held by the geometry, if consistent with its tolerance, or by creating a new
* one
*
* @param curved
* @return
*/
public static CurvedGeometryFactory getFactory(CurvedGeometry<?> curved) {
GeometryFactory factory = ((Geometry) curved).getFactory();
if (factory instanceof CurvedGeometryFactory) {
CurvedGeometryFactory cf = (CurvedGeometryFactory) factory;
if (cf.getTolerance() == curved.getTolerance()) {
return cf;
}
}
return new CurvedGeometryFactory(factory, curved.getTolerance());
}
}
代码示例来源:origin: geotools/geotools
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);
}
}
代码示例来源:origin: geotools/geotools
@DescribeProcess(
title = "Polygonize",
description =
"Creates a set of polygons from linestrings delineating them. The linestrings must be correctly noded (i.e. touch only at endpoints)."
)
@DescribeResult(description = "The collection of created polygons")
public static Geometry polygonize(
@DescribeParameter(name = "geom", description = "Linework to polygonize")
Geometry geom) {
@SuppressWarnings("rawtypes")
List lines = LineStringExtracter.getLines(geom);
Polygonizer polygonizer = new Polygonizer();
polygonizer.add(lines);
@SuppressWarnings("rawtypes")
Collection polys = polygonizer.getPolygons();
Polygon[] polyArray = GeometryFactory.toPolygonArray(polys);
return geom.getFactory().createGeometryCollection(polyArray);
}
代码示例来源:origin: geotools/geotools
public void testGeometryFactoryHint() throws Exception {
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter =
ff.equals(ff.property(aname("stringProperty")), ff.literal("one"));
Query query = new Query();
query.setFilter(filter);
// check we're respecting the geometry factory hint
GeometryFactory gf1 = new GeometryFactory();
query.setHints(new Hints(Hints.JTS_GEOMETRY_FACTORY, gf1));
SimpleFeature f1 = DataUtilities.first(featureSource.getFeatures(query));
assertSame(gf1, ((Geometry) f1.getDefaultGeometry()).getFactory());
// check we're respecting the geometry factory when changing it
GeometryFactory gf2 = new GeometryFactory();
query.setHints(new Hints(Hints.JTS_GEOMETRY_FACTORY, gf2));
SimpleFeature f2 = DataUtilities.first(featureSource.getFeatures(query));
assertSame(gf2, ((Geometry) f2.getDefaultGeometry()).getFactory());
}
内容来源于网络,如有侵权,请联系作者删除!