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 TypeMethodDescriptiondoublearea()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.voidcreates the bounding box
called in the constructor, not needed from outsidebooleanThe Exterior RingReturns the bounding boxThis method returns a point that is typically centered on the geometry.shortReturns the geometry class id.intReturns the geometry type for this geometry.getRings()The rings defining this polygonbooleanhasHoles()interiorRingN(int N) doublelength()Returns the geometry length.intThe 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 PointvoidsetRings(LinearRing[] rings) intsizeOf()Returns an approximation in bytes of the memory used by this geometry.booleanspatiallyEquals(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.voidtranslate(double dx, double dy) Translate this Polygonbooleanvalidate()validate this polygon
ie test if it autointersects and if holes crosse the exteriorRingMethods inherited from class com.kheops.jmap.spatial.DefaultGeometry
spatiallyEqualsMethods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:
createBoundsin 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:
centroidin interfacePolygonTypeGeometry- Specified by:
centroidin interfaceSurface- Returns:
- the center of mass
-
area
public double area()Computes the area of this Polygon -
length
public double length()Description copied from interface:GeometryReturns the geometry length. If the geometry is a surface, then the geometry perimeter shall be returned. -
clone
Clones the current polygon object.- Specified by:
clonein interfaceGeometry- Specified by:
clonein 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:
pointOnSurfacein interfacePolygonTypeGeometry- Specified by:
pointOnSurfacein 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:
spatiallyEqualsin 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:GeometryReturns information about the current geometry. -
polygonIterator
- Specified by:
polygonIteratorin interfacePolygonTypeGeometry
-
translate
public void translate(double dx, double dy) Translate this Polygon -
getGeometryId
public short getGeometryId()Description copied from interface:GeometryReturns the geometry class id. This method is useful for geometry serialization.- Specified by:
getGeometryIdin interfaceGeometry- Returns:
- the geometry id.
-
getGeometryType
public int getGeometryType()Description copied from interface:GeometryReturns the geometry type for this geometry.- Specified by:
getGeometryTypein 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:GeometryThis 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:
getCenteredPointin 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:DefaultGeometryReturns this geometry encoded using the Well-Known Text (WKT) standard.- Specified by:
asTextin interfaceGeometry- Overrides:
asTextin classDefaultGeometry- Returns:
- a WKT geometry.
-