Package com.kheops.jmap.spatial
Class Polygon
java.lang.Object
com.kheops.jmap.spatial.DefaultGeometry
com.kheops.jmap.spatial.Polygon
- All Implemented Interfaces:
Geometry
,PolygonTypeGeometry
,Surface
,Serializable
,Cloneable
- Direct Known Subclasses:
OrientedRectangle
The
It is defined by a exterior ring and a set of non-intersecting rings called holes contained in the exterior ring.
A hole can intersect the exterior ring only on a single point.
Polygon
class defines a polygon in a 2D space. It is defined by a exterior ring and a set of non-intersecting rings called holes contained in the exterior ring.
A hole can intersect the exterior ring only on a single point.
- See Also:
-
Field Summary
FieldsFields inherited from interface com.kheops.jmap.spatial.Geometry
GEOMETRY_ANNOTATION, GEOMETRY_COMPLEX, GEOMETRY_ELLIPSE, GEOMETRY_LINE, GEOMETRY_LINEAR_RING, GEOMETRY_LINESTRING, GEOMETRY_MULTI_ANNOTATION, GEOMETRY_MULTI_LINESTRING, GEOMETRY_MULTI_POINT, GEOMETRY_MULTI_POLYGON, GEOMETRY_POINT, GEOMETRY_POLYGON, GEOMETRY_RECTANGLE
-
Constructor Summary
ConstructorsConstructorDescriptionPolygon()
Polygon
(double[][] tab) Constructs a Polygon given a matrix of double (rings made of points, points are entered as x y in the array), doesn't check if it's valid !Polygon
(LinearRing ring) Constructs a Polygon given a single ring, doesn't check if it's valid !Polygon
(LinearRing[] rings) Constructs a Polygon given rings, doesn't check if it's valid ! -
Method Summary
Modifier and TypeMethodDescriptiondouble
area()
Computes the area of this PolygonasText()
Returns this geometry encoded using the Well-Known Text (WKT) standard.boundary()
The boundary (!= boundingBox) of this polygoncentroid()
Computes the centroid (center of mass) of the polygon, considering possibles holes in it.clone()
Clones the current polygon object.void
creates the bounding box
called in the constructor, not needed from outsideboolean
The Exterior RingReturns the bounding boxThis method returns a point that is typically centered on the geometry.short
Returns the geometry class id.int
Returns the geometry type for this geometry.getRings()
The rings defining this polygonboolean
hasHoles()
interiorRingN
(int N) double
length()
Returns the geometry length.int
The number of holesa Point on this Polygon, in fact the first of the exteriorRing (not in the interior)Point[]
This polygon as an array of Pointvoid
setRings
(LinearRing[] rings) int
sizeOf()
Returns an approximation in bytes of the memory used by this geometry.boolean
spatiallyEquals
(Geometry geometry, PrecisionModel precisionModel) Tests if this Polygon is equal to the argument, on a topological point of vue
it means that they represents the same geometry, even if it is described differently (direction of the rings, order of the rings)
it does not remove additional points on lineString (3 points aligned), one must use smoother.removeExtraPoints() before in order to achieve that.toString()
Returns information about the current geometry.Creates a clone of the current polygon and returns the new instance transformed with the specified geometry transformation.
The returned geometry can be of any geometry types after the transformation.void
translate
(double dx, double dy) Translate this Polygonboolean
validate()
validate this polygon
ie test if it autointersects and if holes crosse the exteriorRingMethods inherited from class com.kheops.jmap.spatial.DefaultGeometry
spatiallyEquals
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.kheops.jmap.spatial.Geometry
spatiallyEquals
-
Field Details
-
rings
the rings defining the polygon. The first is the exterior Ring, others are the holes
-
-
Constructor Details
-
Polygon
public Polygon() -
Polygon
Constructs a Polygon given a single ring, doesn't check if it's valid !- Parameters:
ring
-
-
Polygon
Constructs a Polygon given rings, doesn't check if it's valid !- Parameters:
rings
-
-
Polygon
public Polygon(double[][] tab) Constructs a Polygon given a matrix of double (rings made of points, points are entered as x y in the array), doesn't check if it's valid !- Parameters:
tab
-
-
-
Method Details
-
getBounds
Returns the bounding box -
validate
public boolean validate()validate this polygon
ie test if it autointersects and if holes crosse the exteriorRing- Returns:
-
createBounds
public void createBounds()creates the bounding box
called in the constructor, not needed from outside- Specified by:
createBounds
in interfaceGeometry
-
centroid
Computes the centroid (center of mass) of the polygon, considering possibles holes in it.
it also computes Area, available with getTempArea if needed- Specified by:
centroid
in interfacePolygonTypeGeometry
- Specified by:
centroid
in interfaceSurface
- Returns:
- the center of mass
-
area
public double area()Computes the area of this Polygon -
length
public double length()Description copied from interface:Geometry
Returns the geometry length. If the geometry is a surface, then the geometry perimeter shall be returned. -
clone
Clones the current polygon object.- Specified by:
clone
in interfaceGeometry
- Specified by:
clone
in classDefaultGeometry
- Returns:
-
serialize
This polygon as an array of Point -
exteriorRing
The Exterior Ring- Returns:
-
numInteriorRing
public int numInteriorRing()The number of holes- Returns:
-
interiorRingN
-
boundary
The boundary (!= boundingBox) of this polygon -
pointOnSurface
a Point on this Polygon, in fact the first of the exteriorRing (not in the interior)- Specified by:
pointOnSurface
in interfacePolygonTypeGeometry
- Specified by:
pointOnSurface
in interfaceSurface
- Returns:
- a point on thge surface.
-
getRings
The rings defining this polygon- Returns:
-
setRings
- Parameters:
rings
-
-
hasHoles
public boolean hasHoles() -
spatiallyEquals
Tests if this Polygon is equal to the argument, on a topological point of vue
it means that they represents the same geometry, even if it is described differently (direction of the rings, order of the rings)
it does not remove additional points on lineString (3 points aligned), one must use smoother.removeExtraPoints() before in order to achieve that.- Specified by:
spatiallyEquals
in interfaceGeometry
- Parameters:
geometry
-precisionModel
- the precision model to use while comparing geometries.- Returns:
- whether both geometries are spatially equals.
-
equals
-
toString
Description copied from interface:Geometry
Returns information about the current geometry. -
polygonIterator
- Specified by:
polygonIterator
in interfacePolygonTypeGeometry
-
translate
public void translate(double dx, double dy) Translate this Polygon -
getGeometryId
public short getGeometryId()Description copied from interface:Geometry
Returns the geometry class id. This method is useful for geometry serialization.- Specified by:
getGeometryId
in interfaceGeometry
- Returns:
- the geometry id.
-
getGeometryType
public int getGeometryType()Description copied from interface:Geometry
Returns the geometry type for this geometry.- Specified by:
getGeometryType
in interfaceGeometry
- Returns:
- the geometry type.
- See Also:
-
transform
Creates a clone of the current polygon and returns the new instance transformed with the specified geometry transformation.
The returned geometry can be of any geometry types after the transformation. -
getCenteredPoint
Description copied from interface:Geometry
This method returns a point that is typically centered on the geometry. If the geometry is a point, the point is returned. If it is a line, a point on the curve interpolated at 50% is returned. If the geometry is a surface, the centroid is returned if it is inside the polygon, if not, a point inside the polygon (but likely not exactly in the center) will be returned. If the geometry is a collection, the method is called on the first part of the collection.- Specified by:
getCenteredPoint
in interfaceGeometry
- Returns:
- a point likely at the center of the geometry
- See Also:
-
sizeOf
public int sizeOf()Returns an approximation in bytes of the memory used by this geometry. -
asText
Description copied from class:DefaultGeometry
Returns this geometry encoded using the Well-Known Text (WKT) standard.- Specified by:
asText
in interfaceGeometry
- Overrides:
asText
in classDefaultGeometry
- Returns:
- a WKT geometry.
-