public class JtsShapeFactory extends ShapeFactoryImpl
ShapeFactoryImpl
with support for Polygons
using JTS.
To the extent possible, our JtsGeometry
adds some amount of geodetic support over
vanilla JTS which only has a Euclidean (flat plane) model.ShapeFactoryImpl.GeneralShapeMultiShapeBuilder<T extends Shape>
ShapeFactory.LineStringBuilder, ShapeFactory.MultiLineStringBuilder, ShapeFactory.MultiPointBuilder, ShapeFactory.MultiPolygonBuilder, ShapeFactory.MultiShapeBuilder<T extends Shape>, ShapeFactory.PointsBuilder<T>, ShapeFactory.PolygonBuilder
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowMultiOverlap |
protected boolean |
autoIndex |
protected DatelineRule |
datelineRule |
protected static LinearRing[] |
EMPTY_HOLES |
protected GeometryFactory |
geometryFactory |
protected boolean |
useJtsLineString |
protected boolean |
useJtsMulti |
protected boolean |
useJtsPoint |
protected ValidationRule |
validationRule |
ctx
Constructor and Description |
---|
JtsShapeFactory(JtsSpatialContext ctx,
JtsSpatialContextFactory factory)
Called by
JtsSpatialContextFactory.newSpatialContext() . |
Modifier and Type | Method and Description |
---|---|
DatelineRule |
getDatelineRule()
Returns the rule used to handle geometry objects that have dateline (aka anti-meridian) crossing considerations.
|
GeometryFactory |
getGeometryFactory() |
Geometry |
getGeometryFrom(Shape shape)
|
ValidationRule |
getValidationRule()
Returns the rule used to handle errors when creating a JTS
Geometry , particularly after it has been
read from one of the ShapeReader s. |
boolean |
isAllowMultiOverlap()
If geom might be a multi geometry of some kind, then might multiple
component geometries overlap? Strict OGC says this is invalid but we
can accept it by computing the union.
|
boolean |
isAutoIndex()
If JtsGeometry shapes should be automatically "prepared" (i.e.
|
ShapeFactory.LineStringBuilder |
lineString()
(Builder) Constructs a line string, with a possible buffer.
|
Shape |
lineString(List<Point> points,
double bufferDistance)
Constructs a line string with a possible buffer.
|
Rectangle |
makeRectFromRectangularPoly(Geometry geom)
INTERNAL: Returns a Rectangle of the JTS
Envelope (bounding box) of the given geom . |
JtsGeometry |
makeShape(Geometry geom)
|
JtsGeometry |
makeShape(Geometry geom,
boolean dateline180Check,
boolean allowMultiOverlap)
INTERNAL
|
Shape |
makeShapeFromGeometry(Geometry geom)
INTERNAL Usually creates a JtsGeometry, potentially validating, repairing, and indexing ("preparing").
|
ShapeFactory.MultiLineStringBuilder |
multiLineString()
(Builder) Constructs a MultiLineString, or possibly the result of that buffered.
|
ShapeFactory.MultiPointBuilder |
multiPoint()
(Builder) Constructs a MultiPoint.
|
ShapeFactory.MultiPolygonBuilder |
multiPolygon()
(Builder) Constructs a MultiPolygon.
|
<T extends Shape> |
multiShape(Class<T> shapeClass)
(Builder) Constructs a Shape aggregate in which each component/member
is an instance of the specified class.
|
double |
normDist(double d)
Called to normalize a value that isn't X or Y or Z.
|
double |
normX(double x)
Normalize the 'x' dimension.
|
double |
normY(double y) |
double |
normZ(double z)
(disclaimer: the Z dimension isn't fully supported)
|
Point |
pointXY(double x,
double y)
Construct a point.
|
Point |
pointXYZ(double x,
double y,
double z)
Construct a point of 3 dimensions.
|
ShapeFactory.PolygonBuilder |
polygon()
(Builder) Constructs a polygon.
|
boolean |
useJtsLineString()
Should
lineString(java.util.List,double) return JtsGeometry ? |
boolean |
useJtsMulti()
Whether
multiPoint() , multiLineString() , and multiPolygon() should all use JTS's
subclasses of GeometryCollection instead of Spatial4j's basic impl. |
boolean |
useJtsPoint()
Should
pointXY(double, double) return JtsPoint ? |
circle, circle, getSpatialContext, isNormWrapLongitude, multiShape, rect, rect, verifyX, verifyY, verifyZ
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
pointLatLon
protected static final LinearRing[] EMPTY_HOLES
protected final GeometryFactory geometryFactory
protected final boolean allowMultiOverlap
protected final boolean useJtsPoint
protected final boolean useJtsLineString
protected final boolean useJtsMulti
protected final DatelineRule datelineRule
protected final ValidationRule validationRule
protected final boolean autoIndex
public JtsShapeFactory(JtsSpatialContext ctx, JtsSpatialContextFactory factory)
JtsSpatialContextFactory.newSpatialContext()
.public boolean isAllowMultiOverlap()
ShapeCollection.relateContainsShortCircuits()
.public DatelineRule getDatelineRule()
public ValidationRule getValidationRule()
Geometry
, particularly after it has been
read from one of the ShapeReader
s.public boolean isAutoIndex()
ShapeReader
.JtsGeometry.index()
public double normX(double x)
ShapeFactory
ShapeReader
s before creating a shape.normX
in interface ShapeFactory
normX
in class ShapeFactoryImpl
public double normY(double y)
normY
in interface ShapeFactory
normY
in class ShapeFactoryImpl
ShapeFactory.normX(double)
public double normZ(double z)
ShapeFactory
normZ
in interface ShapeFactory
normZ
in class ShapeFactoryImpl
ShapeFactory.normX(double)
public double normDist(double d)
ShapeFactory
SpatialContext.normX(double)
& normY & normZ. This
is called by a ShapeReader
before creating a shape.normDist
in interface ShapeFactory
normDist
in class ShapeFactoryImpl
public Geometry getGeometryFrom(Shape shape)
Geometry
for the given Shape
. Some shapes hold a
JTS geometry whereas new ones must be created for the rest.shape
- Not nullpublic boolean useJtsPoint()
pointXY(double, double)
return JtsPoint
?public Point pointXY(double x, double y)
ShapeFactory
pointXY
in interface ShapeFactory
pointXY
in class ShapeFactoryImpl
public Point pointXYZ(double x, double y, double z)
ShapeFactory
pointXYZ
in interface ShapeFactory
pointXYZ
in class ShapeFactoryImpl
public boolean useJtsLineString()
lineString(java.util.List,double)
return JtsGeometry
?public Shape lineString(List<Point> points, double bufferDistance)
ShapeFactory
lineString
in interface ShapeFactory
lineString
in class ShapeFactoryImpl
public ShapeFactory.LineStringBuilder lineString()
ShapeFactory
lineString
in interface ShapeFactory
lineString
in class ShapeFactoryImpl
public ShapeFactory.PolygonBuilder polygon()
ShapeFactory
polygon
in interface ShapeFactory
polygon
in class ShapeFactoryImpl
public boolean useJtsMulti()
multiPoint()
, multiLineString()
, and multiPolygon()
should all use JTS's
subclasses of GeometryCollection
instead of Spatial4j's basic impl. The general multiShape(Class)
will never use GeometryCollection
because that class doesn't support relations.public ShapeFactory.MultiPointBuilder multiPoint()
ShapeFactory
multiPoint
in interface ShapeFactory
multiPoint
in class ShapeFactoryImpl
public ShapeFactory.MultiLineStringBuilder multiLineString()
ShapeFactory
multiLineString
in interface ShapeFactory
multiLineString
in class ShapeFactoryImpl
public ShapeFactory.MultiPolygonBuilder multiPolygon()
ShapeFactory
multiPolygon
in interface ShapeFactory
multiPolygon
in class ShapeFactoryImpl
public <T extends Shape> ShapeFactory.MultiShapeBuilder<T> multiShape(Class<T> shapeClass)
ShapeFactory
multiShape
in interface ShapeFactory
multiShape
in class ShapeFactoryImpl
public Shape makeShapeFromGeometry(Geometry geom)
ShapeReader
instances.
If given a direct instance of GeometryCollection
then it's contents will be
recursively converted and then the resulting list will be passed to
SpatialContext.makeCollection(List)
and returned.
If given a Point
then SpatialContext.makePoint(double, double)
is called, which will return a JtsPoint
if JtsSpatialContext.useJtsPoint()
; otherwise
a standard Spatial4j Point is returned.
If given a LineString
and if JtsSpatialContext.useJtsLineString()
is true then
then the geometry's parts are exposed to call SpatialContext.makeLineString(List)
.public JtsGeometry makeShape(Geometry geom, boolean dateline180Check, boolean allowMultiOverlap)
geom
- Non-nulldateline180Check
- if both this is true and SpatialContext.isGeo()
, then JtsGeometry will check
for adjacent coordinates greater than 180 degrees longitude apart, and
it will do tricks to make that line segment (and the shape as a whole)
cross the dateline even though JTS doesn't have geodetic support.allowMultiOverlap
- See isAllowMultiOverlap()
.makeShape(org.locationtech.jts.geom.Geometry)
public JtsGeometry makeShape(Geometry geom)
Shape
from a JTS Geometry
. Generally, this shouldn't be
called when one of the other factory methods are available, such as for points. The caller
needs to have done some verification/normalization of the coordinates by now, if any. Also,
note that direct instances of GeometryCollection
isn't supported.
Instead of calling this method, consider makeShapeFromGeometry(Geometry)
whichpublic GeometryFactory getGeometryFactory()
public Rectangle makeRectFromRectangularPoly(Geometry geom)
Envelope
(bounding box) of the given geom
. This asserts
that Geometry.isRectangle()
is true. This method reacts to the DatelineRule
setting.geom
- non-nullCopyright © 2020 LocationTech. All rights reserved.