Interface Geometry
- All Superinterfaces:
Cloneable,Comparable,Serializable,Shape
- All Known Subinterfaces:
Aggregate,Arc,Circle,Circumference,Complex,Composite,CompositeCurve,CompositeSolid,CompositeSurface,Curve,Ellipse,EllipticArc,FilledSpline,Line,MultiCurve,MultiLine,MultiPoint,MultiPolygon,MultiPrimitive,MultiSolid,MultiSurface,NullGeometry,OrientableCurve,OrientablePrimitive,OrientableSurface,PeriEllipse,Point,PointM,Polygon,Primitive,Ring,Solid,Spline,Surface
This interface is equivalent to the GM_Object specified in ISO 19107. It is the root class of the geometric object taxonomy and supports interfaces common to all geographically referenced geometric objects.
Geometry instances are sets of direct positions in a particular coordinate reference system. A Geometry can be regarded as an infinite set of points that satisfies the set operation interfaces for a set of direct positions.
A geometric object shall be a combination of a coordinate geometry and a coordinate reference system. In all of the operations, all geometric calculations shall be done in the coordinate reference system of the first geometric object accessed, which is normally the object whose operation is being invoked. Returned objects shall be in the coordinate reference system in which the calculations are done unless explicitly stated otherwise.
This class extends of the Shape class by historical reasons but this
inheritance will disappear in future versions.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacestatic interfacestatic interfaceThe subtype of a geometry is related with the dimension of the geometry, that is a combination between the spatial dimension (2D, 2ZD, 3D) and the M coordinate or "measure".static interfacePredefined geometry types in the model.static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intEast.static final intInitial value for new geometry subtypes (it must not overlap with the basic ones defined in SUBTYPES).static final intInitial value for new geometry types (it must not overlap with the basic ones defined in TYPES).static final intSpecifies a bevel join style for buffer.static final intSpecifies a mitre join style for buffer.static final intSpecifies a round join style for buffer.static final intNorth.static final intNorth - East.static final intNorth - West.static final intSouth.static final intSouth - East.static final intstatic final intstatic final intSouth - West.static final intWest. -
Method Summary
Modifier and TypeMethodDescriptiondoublearea()boundary()Return the boundarybuffer(double distance) Computes a buffer area around this geometry having the given width This is a utility method to wrap the invocation to the operationGeometry.OPERATIONS.BUFFER.buffer(double distance, int joinStyle, boolean capButt) Computes a buffer area around this geometry having the given width, the joinStyle and the capButt This is a utility method to wrap the invocation to the operationGeometry.OPERATIONS.BUFFER.booleancanBeReprojected(org.gvsig.crs.projection.lib.CoordinateTransformation ct) Return true if the geometry can be reprojected by the coordinate transformationbooleanReturn true if the geometry can be transformed by the affine transformcentroid()clone()Creates a clone of this geometry.Geometry[]closestPoints(Geometry other) booleanTests whether this geometry contains the specified geometry.byte[]Return a byte array with the equivalent in EWKB format of the Geometry.byte[]convertToEWKB(int srs) byte[]convertToEWKBForcingType(int srs, int type) convertToGeoJson(Map<String, Object> properties, boolean encodecrs) byte[]Return a byte array with the equivalent in WKB format of the Geometry.byte[]convertToWKB(int srs) byte[]convertToWKBForcingType(int srs, int type) byte[]Return a string with the equivalent in WKT format of the Geometry.booleanbooleanbooleandifference(Geometry other) booleandoubleReturns the minimum distance between this Geometry and the specified geometry.booleanensureOrientation(boolean ccw) Ensures the orientation of the geometry according to the parameter, flipping it if necessary.booleanbooleanfastIntersects(double x, double y, double w, double h) Used by the drawing strategies to quickly test whether this geometry intersects with the visible rectangle.fix()voidflip()Flip the coordinates of the geometry.force2D()forceSubtype(int subtype) Returns this geometry's boundary rectangle.intReturns the largest number n such that each direct position in a geometric set can be associated with a subset that has the direct position in its interior and is similar (isomorphic) to Rn, Euclidean n-space.Returns the minimum bounding box for this Geometry.Get GeneralPathIterator, to do registered operations to it.Instance of the GeometryType associated to this geometry.Handler[]getHandlers(int type) It returns the handlers of the geometry, these they can be of two types is straightening and of selection.This method returns a point which is inside the geometry.Useful to have the real shape behind the scenes.If applies an affine transformation and returns the GeneralPathXIterator with this geometry's information.getPathIterator(AffineTransform at, double flatness) If applies an affine transformation and returns the GeneralPathXIterator with this geometry's information.org.gvsig.crs.projection.lib.ProjectiongetShape()getShape(AffineTransform affineTransform) intgetType()If this geometry is a predefined interface then this method returns one ofGeometry.TYPEScontants.
If this geometry is an extended type then this method returns a runtime constant that identifies its type.Check if the geometry is valid and returns the validation status.intersection(Geometry other) booleanReturns true if this geometry intersects the rectangle passed as parameter.booleanintersects(Geometry geometry) invokeOperation(int index, GeometryOperationContext ctx) Invokes a geometry operation given its index and context.invokeOperation(String opName, GeometryOperationContext ctx) Invokes a geometry operation given its name and context.booleanisCCW()booleanisEmpty()booleanisSimple()Returnstrueif this Geometry has no interior point of self-intersection or self-tangency.booleanisValid()Check if the geometry is valid.booleanisWithinDistance(Geometry other, double distance) Try to fix the geometry and return the new geometry.voidmove(double dx, double dy) Shifts geometry by given amount in x and y axesoffset(double distance) offset(int joinStyle, double distance) booleanReturns true if passed as a parameter geometry is completely out of geometry.booleanTests whether this geometry overlaps the specified geometry.doublevoidreProject(org.gvsig.crs.projection.lib.CoordinateTransformation ct) Reprojects this geometry by the coordinate transformer passed as parameter.voidrotate(double radAngle, double basex, double basey) Rotates the geometry by radAngle radians using the given coordinates as center of rotation.voidScales geometry in x and y axes by given scale factors using the given point as center of projection.voidsetProjection(String projection) voidsetProjection(org.gvsig.crs.projection.lib.Projection projection) voidsetProjectionIffNull(org.gvsig.crs.projection.lib.Projection projection) toLines()Converts the geometry to be lines and makes with them a multiLinetoPoints()Converts the geometry to be points and makes with them a multiPointConverts the geometry to be polygons and makes with them a multiPolygonbooleanvoidIt applies an affine transformation to the geometry.booleanMethods inherited from interface java.lang.Comparable
compareTo
-
Field Details
-
JOIN_STYLE_ROUND
static final int JOIN_STYLE_ROUNDSpecifies a round join style for buffer.- See Also:
-
JOIN_STYLE_MITRE
static final int JOIN_STYLE_MITRESpecifies a mitre join style for buffer.- See Also:
-
JOIN_STYLE_BEVEL
static final int JOIN_STYLE_BEVELSpecifies a bevel join style for buffer.- See Also:
-
EXTENDED_GEOMTYPE_OFFSET
static final int EXTENDED_GEOMTYPE_OFFSETInitial value for new geometry types (it must not overlap with the basic ones defined in TYPES).- See Also:
-
EXTENDED_GEOMSUBTYPE_OFFSET
static final int EXTENDED_GEOMSUBTYPE_OFFSETInitial value for new geometry subtypes (it must not overlap with the basic ones defined in SUBTYPES).- See Also:
-
BEST
static final int BEST- See Also:
-
N
static final int NNorth.- See Also:
-
NE
static final int NENorth - East.- See Also:
-
E
static final int EEast.- See Also:
-
SE
static final int SESouth - East.- See Also:
-
S
static final int SSouth.- See Also:
-
SW
static final int SWSouth - West.- See Also:
-
W
static final int WWest.- See Also:
-
NW
static final int NWNorth - West.- See Also:
-
SELECTHANDLER
static final int SELECTHANDLER- See Also:
-
STRETCHINGHANDLER
static final int STRETCHINGHANDLER- See Also:
-
-
Method Details
-
getType
int getType()If this geometry is a predefined interface then this method returns one ofGeometry.TYPEScontants.
If this geometry is an extended type then this method returns a runtime constant that identifies its type. By convention this value is stored in a constant called .CODE within the geometry class, for instance: Point2D.CODE.- Returns:
- If this geometry is a predefined interface then one of
Geometry.TYPESor a runtime constant if it is an extended type.
-
cloneGeometry
Geometry cloneGeometry()Creates a clone of this geometry.- Returns:
- A clone of this geometry.
-
clone
- Throws:
CloneNotSupportedException
-
intersects
Returns true if this geometry intersects the rectangle passed as parameter.- Specified by:
intersectsin interfaceShape- Parameters:
r- Rectangle.- Returns:
- True, if
thisintersectsr.
-
fastIntersects
boolean fastIntersects(double x, double y, double w, double h) Used by the drawing strategies to quickly test whether this geometry intersects with the visible rectangle.- Parameters:
x- The minimum X coordinate.y- The minimum Y coordinate.w- The width of the envelope.h- The height of the envelope.- Returns:
- true if
thisintersects the rectangle defined by the parameters.
-
getEnvelope
Envelope getEnvelope()Returns the minimum bounding box for this Geometry. This shall be the coordinate region spanning the minimum and maximum value for each ordinate taken on by DirectPositions in this Geometry. The simplest representation for an envelope consists of two DirectPositions, the first one containing all the minimums for each ordinate, and second one containing all the maximums.
- Returns:
- The minimum bounding box for this Geometry.
-
reProject
void reProject(org.gvsig.crs.projection.lib.CoordinateTransformation ct) Reprojects this geometry by the coordinate transformer passed as parameter.- Parameters:
ct- Coordinate Transformer.
-
transform
It applies an affine transformation to the geometry. If parameter value is null, it will be considered an empty transformation, therefore equivalent to the identity transformation.- Parameters:
at- The transformation to apply.
-
getDimension
int getDimension()Returns the largest number n such that each direct position in a geometric set can be associated with a subset that has the direct position in its interior and is similar (isomorphic) to Rn, Euclidean n-space.- Returns:
- The dimension.
-
isSimple
boolean isSimple()Returnstrueif this Geometry has no interior point of self-intersection or self-tangency. In mathematical formalisms, this means that every point in the interior of the object must have a metric neighborhood whose intersection with the object is isomorphic to an n-sphere, where n is the dimension of this Geometry.- Returns:
- If the geometry is simple.
-
isCCW
-
invokeOperation
Object invokeOperation(int index, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException Invokes a geometry operation given its index and context.- Parameters:
index- Unique index of the operation. Operation code.ctx- The context of the geometry operation.- Returns:
- Object returned by the operation.
- Throws:
GeometryOperationNotSupportedException- It is thrown when the operation has been not registered for this geometry.GeometryOperationException- It is thrown when there is an error executing the operation.
-
invokeOperation
Object invokeOperation(String opName, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException Invokes a geometry operation given its name and context.- Parameters:
opName- Operation name.ctx- The context of the geometry operation.- Returns:
- Object returned by the operation.
- Throws:
GeometryOperationNotSupportedException- It is thrown when the operation has been not registered for this geometry.GeometryOperationException- It is thrown when there is an error executing the operation.
-
getGeometryType
GeometryType getGeometryType()Instance of the GeometryType associated to this geometry.- Returns:
- The geometry type.
-
convertTo
Object convertTo(String format, Object... args) throws GeometryOperationNotSupportedException, GeometryOperationException -
convertToGeoJson
String convertToGeoJson(Map<String, Object> properties, boolean encodecrs) throws GeometryOperationNotSupportedException, GeometryOperationException -
convertToWKB
Return a byte array with the equivalent in WKB format of the Geometry. Utility method to wrap the invocation to the operationGeometry.OPERATIONS.CONVERTTOWKB.- Returns:
- the WKB version of the geometry
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
convertToHexEWKB
-
convertToHexWKB
-
convertToWKBQuietly
byte[] convertToWKBQuietly() -
convertToHexWKBQuietly
String convertToHexWKBQuietly() -
convertToHexEWKBQuietly
String convertToHexEWKBQuietly() -
convertToWKB
byte[] convertToWKB(int srs) throws GeometryOperationNotSupportedException, GeometryOperationException -
convertToWKBForcingType
byte[] convertToWKBForcingType(int srs, int type) throws GeometryOperationNotSupportedException, GeometryOperationException -
convertToEWKB
Return a byte array with the equivalent in EWKB format of the Geometry. Utility method to wrap the invocation to the operationGeometry.OPERATIONS.CONVERTTOWKB.- Returns:
- the EWKB version of the geometry
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
convertToEWKB
byte[] convertToEWKB(int srs) throws GeometryOperationNotSupportedException, GeometryOperationException -
convertToEWKBForcingType
byte[] convertToEWKBForcingType(int srs, int type) throws GeometryOperationNotSupportedException, GeometryOperationException -
convertToWKT
Return a string with the equivalent in WKT format of the Geometry. This is a utility method to wrap the invocation to the operationGeometry.OPERATIONS.CONVERTTOWKT.- Returns:
- the WKT version of the geometry.
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
convertToWKTQuietly
String convertToWKTQuietly() -
buffer
Geometry buffer(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException Computes a buffer area around this geometry having the given width This is a utility method to wrap the invocation to the operationGeometry.OPERATIONS.BUFFER.- Parameters:
distance- the width of the buffer- Returns:
- a new Geometry with the computed buffer.
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
buffer
Geometry buffer(double distance, int joinStyle, boolean capButt) throws GeometryOperationNotSupportedException, GeometryOperationException Computes a buffer area around this geometry having the given width, the joinStyle and the capButt This is a utility method to wrap the invocation to the operationGeometry.OPERATIONS.BUFFER.- Parameters:
distance- the width of the bufferjoinStyle- the join style can be JOIN_STYLE_ROUND, JOIN_STYLE_MITRE, JOIN_STYLE_BEVEL,capButt- true if not add a cap- Returns:
- a new Geometry with the computed buffer.
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
offset
Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException - Parameters:
distance-- Returns:
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
offset
Geometry offset(int joinStyle, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException - Parameters:
joinStyle-distance-- Returns:
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
contains
boolean contains(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException Tests whether this geometry contains the specified geometry. This is a utility method to wrap the invocation to the operationGeometry.OPERATIONS.CONTAINS.- Parameters:
geometry- the Geometry with which to compare this Geometry- Returns:
- if this Geometry contains the specified geometry
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
distance
double distance(Geometry other) throws GeometryOperationNotSupportedException, GeometryOperationException Returns the minimum distance between this Geometry and the specified geometry. This is a utility method to wrap the invocation to the operationGeometry.OPERATIONS.DISTANCE.- Parameters:
other-- Returns:
- the distance between the geometries
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
closestPoints
Geometry[] closestPoints(Geometry other) throws GeometryOperationNotSupportedException, GeometryOperationException -
isWithinDistance
boolean isWithinDistance(Geometry other, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException -
overlaps
boolean overlaps(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException Tests whether this geometry overlaps the specified geometry. This is a utility method to wrap the invocation to the operationGeometry.OPERATIONS.OVERLAPS.- Parameters:
geometry- the Geometry with which to compare this Geometry- Returns:
- true if the two geometries overlap.
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
convexHull
-
coveredBy
boolean coveredBy(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException -
covers
boolean covers(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException -
crosses
boolean crosses(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException -
difference
Geometry difference(Geometry other) throws GeometryOperationNotSupportedException, GeometryOperationException -
disjoint
boolean disjoint(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException -
intersection
Geometry intersection(Geometry other) throws GeometryOperationNotSupportedException, GeometryOperationException -
intersects
boolean intersects(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException -
snapTo
Geometry snapTo(Geometry other, double snapTolerance) throws GeometryOperationNotSupportedException, GeometryOperationException -
touches
boolean touches(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException -
union
Geometry union(Geometry other) throws GeometryOperationNotSupportedException, GeometryOperationException -
within
boolean within(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException -
centroid
-
getInteriorPoint
This method returns a point which is inside the geometry. This is useful for mathematical purposes but it is very unlikely to be a suitable place for a label, for example.- Returns:
- an interior point
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
area
-
perimeter
-
rotate
void rotate(double radAngle, double basex, double basey) Rotates the geometry by radAngle radians using the given coordinates as center of rotation. Rotating with a positive angle rotates points on the positive x axis toward the positive y axis. In most cases, we assume x increases rightwards and y increases upwards, so in most cases, a positive angle will mean counter-clockwise rotation.- Parameters:
radAngle- the amount of rotation, in radiansbasex- x coordinate of center of rotationbasey- y coordinate of center of rotation
-
move
void move(double dx, double dy) Shifts geometry by given amount in x and y axes- Parameters:
dx-dy-
-
scale
Scales geometry in x and y axes by given scale factors using the given point as center of projection.- Parameters:
basePoint-sx- scale factor in x axissy- scale factor in y axis
-
isValid
boolean isValid()Check if the geometry is valid.- Returns:
- true if the geometry is valid.
-
getValidationStatus
Geometry.ValidationStatus getValidationStatus()Check if the geometry is valid and returns the validation status.- Returns:
- the ValidationStatus
-
makeValid
Geometry makeValid()Try to fix the geometry and return the new geometry. If the geometry is valid return the same geometry. If the geometry is corrupt or can't fix it, return null.- Returns:
- the new fixed geometry
-
getShape
- Parameters:
affineTransform-- Returns:
- the awt shape used to display the geometry. It applies a tranformation before to return the coordinates of the shape
-
getShape
Shape getShape()- Returns:
- the awt shape used to display the geometry.
-
getBounds2D
Rectangle2D getBounds2D()Returns this geometry's boundary rectangle.- Specified by:
getBounds2Din interfaceShape- Returns:
- Boundary rectangle.
-
getPathIterator
If applies an affine transformation and returns the GeneralPathXIterator with this geometry's information.- Specified by:
getPathIteratorin interfaceShape- Parameters:
at- The transformation to apply.- Returns:
- The GeneralPathXIterator with this geometry's information.
-
getHandlers
It returns the handlers of the geometry, these they can be of two types is straightening and of selection.- Parameters:
type- Type of handlers.- Returns:
- The handlers.
-
getPathIterator
If applies an affine transformation and returns the GeneralPathXIterator with this geometry's information.- Specified by:
getPathIteratorin interfaceShape- Parameters:
at- The affine transformation.flatness-- Returns:
- The GeneralPathXIterator with this geometry's information.
-
getInternalShape
Shape getInternalShape()Useful to have the real shape behind the scenes. May be uses to edit it knowing it it is a Circle, Ellipse, etc.- Returns:
- The awt shape
-
getGeneralPath
GeneralPathX getGeneralPath()Get GeneralPathIterator, to do registered operations to it.- Returns:
- The GeneralPathX.
-
toPoints
Converts the geometry to be points and makes with them a multiPoint- Returns:
- MultiPoint
- Throws:
GeometryException
-
toLines
Converts the geometry to be lines and makes with them a multiLine- Returns:
- Throws:
GeometryException
-
toPolygons
Converts the geometry to be polygons and makes with them a multiPolygon- Returns:
- Throws:
GeometryException
-
flip
Flip the coordinates of the geometry. If the geometry is aggregate also revert the primitives collection. -
ensureOrientation
boolean ensureOrientation(boolean ccw) throws GeometryOperationNotSupportedException, GeometryOperationException Ensures the orientation of the geometry according to the parameter, flipping it if necessary. If the geometry is a polygon, ensures the orientation of its perimeter and ensures the opposite orientation of their holes.- Parameters:
ccw-- Returns:
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
out
boolean out(Geometry geometry) throws GeometryOperationNotSupportedException, GeometryOperationException Returns true if passed as a parameter geometry is completely out of geometry.- Parameters:
geometry-- Returns:
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
force2D
- Returns:
- Throws:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
forceSubtype
Geometry forceSubtype(int subtype) throws GeometryOperationNotSupportedException, GeometryOperationException -
canBeTransformed
Return true if the geometry can be transformed by the affine transform- Parameters:
at- the affine transform- Returns:
-
canBeReprojected
boolean canBeReprojected(org.gvsig.crs.projection.lib.CoordinateTransformation ct) Return true if the geometry can be reprojected by the coordinate transformation- Parameters:
ct- the coordinate transformation- Returns:
-
setProjection
-
setProjection
void setProjection(org.gvsig.crs.projection.lib.Projection projection) -
setProjectionIffNull
void setProjectionIffNull(org.gvsig.crs.projection.lib.Projection projection) -
getProjection
org.gvsig.crs.projection.lib.Projection getProjection() -
boundary
Geometry boundary()Return the boundary- Returns:
-
equals
-
fix
Geometry fix() -
isEmpty
boolean isEmpty()
-