MorphAL 0.1

fr.ign.cogit.alpage.morphal.geometry
Class PolygonUtil

java.lang.Object
  extended by fr.ign.cogit.alpage.morphal.geometry.PolygonUtil

public class PolygonUtil
extends java.lang.Object

Geometric methods to manipulate geometric features with Polygon and MultiPolygon types, and to compute indices.

Version:
0.1 (2011-01-09)
Author:
Eric Grosso - IGN / Laboratoire COGIT

Constructor Summary
PolygonUtil()
           
 
Method Summary
static MultiPolygon cleaningMultiPolygonShape(MultiPolygon multiPolygon, double threshold)
          Clean a MultiPolygon by removing the unuseful points (in regard to the chosen threshold) of a MultiPolygon, i.e. the points which are in the alignment between the previous point and the following one.
static MultiPolygon cleaningMultiPolygonShapeAutomaticThreshold(MultiPolygon multiPolygon)
          Clean a MultiPolygon by removing the unuseful points (in regard to the chosen threshold) of a MultiPolygon, i.e. the points which are in the alignment between the previous point and the following one.
static Polygon cleaningPolygonShape(Polygon polygon, double threshold)
          Clean a Polygon by removing the unuseful points (in regard to the chosen threshold) of a Polygon, i.e. the points which are in the alignment between the previous point and the following one.
static Polygon cleaningPolygonShapeAutomaticThreshold(Polygon polygon)
          Clean a Polygon by removing the unuseful points (in regard to the chosen threshold) of a Polygon, i.e. the points which are in the alignment between the previous point and the following one.
static double compactednessIndex(Polygon polygon)
          Compute the compactedness index of a Polygon, i.e.
static double elongation(Polygon rectangle)
          (Input parameter: The Polygon must be a rectangle) Compute the elongation of a rectangle, equals to the ratio length / width.
static boolean isCircle(Polygon polygon, double iMillerThreshold)
          Compute if a Polygon has a circular shape or not, based on the compactedness index or Miller's index (if Miller's index equals 1, it means that the shape is a perfect circle).
static double isRectangle(double sdConvexHull, double sdConvexHullThreshold, double sdMBR, double sdMBRThreshold, Polygon mbr)
          Compute if a Polygon has a rectangular shape or not, based on the comparison with two shapes: the shape of the minimum bounding rectangle of the Polygon, and the shape of the convex hull associated to the Polygon.
static double isRectangle(Polygon polygon, double sdConvexHullThreshold, double sdMBRThreshold)
          Compute if a Polygon has a rectangular shape or not, based on the comparison with two shapes: the shape of the minimum bounding rectangle of the Polygon, and the shape of the convex hull associated to the Polygon.
static Polygon MBR(Polygon polygon)
          Compute the minimum bounding rectangle (MBR) of a Polygon.
static double orientation(Polygon polygon)
          Compute the orientation of a Polygon (in degrees) comparatively to the cartographic East (axis X).
static Polygon rotation(Polygon polygon, Coordinate center, double angle)
          Compute the rotation of a Polygon.
static double surfaceDistance(Geometry geometryA, Geometry geometryB)
          Compute the surface distance between two Geometrys.
static double surfaceDistance(Polygon polygonA, Polygon polygonB)
          Compute the surface distance between two Polygons.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PolygonUtil

public PolygonUtil()
Method Detail

compactednessIndex

public static double compactednessIndex(Polygon polygon)
Compute the compactedness index of a Polygon, i.e. Miller's index, 4.Pi.area / perimeter^2.

Parameters:
polygon - polygon to process
Returns:
the compactedness index of the polygon

surfaceDistance

public static double surfaceDistance(Polygon polygonA,
                                     Polygon polygonB)
Compute the surface distance between two Polygons. Surface distance is a number between 0 and 1, computed thanks to the following formula: 1 - (area(intersection) / area(union)).

Parameters:
polygonA - first polygon to process
polygonB - second polygon to process
Returns:
the surface distance between polygon A and polygon B

surfaceDistance

public static double surfaceDistance(Geometry geometryA,
                                     Geometry geometryB)
Compute the surface distance between two Geometrys. Surface distance is a number between 0 and 1, computed thanks to the following formula: 1 - (area(intersection) / area(union)).

Parameters:
geometryA - first geometry to process
geometryB - second geometry to process
Returns:
the surface distance between geometry A and geometry B

rotation

public static Polygon rotation(Polygon polygon,
                               Coordinate center,
                               double angle)
Compute the rotation of a Polygon.

Parameters:
polygon - polygon to process
center - rotation center
angle - rotation angle
Returns:
the rotated polygon

MBR

public static Polygon MBR(Polygon polygon)
Compute the minimum bounding rectangle (MBR) of a Polygon.

Parameters:
polygon - polygon to process
Returns:
the mimimum bounding rectangle, or null if the MBR can not be computed

elongation

public static double elongation(Polygon rectangle)
(Input parameter: The Polygon must be a rectangle) Compute the elongation of a rectangle, equals to the ratio length / width. If the Polygon in parameter has a number of coordinates different from 5, the value -1.0 is returned.

Parameters:
rectangle - a polygon which must be a rectangle
Returns:
the elongation of the rectangle

orientation

public static double orientation(Polygon polygon)
Compute the orientation of a Polygon (in degrees) comparatively to the cartographic East (axis X). The orientation is based on the orientation of the associated minimum bounding rectangle. Its value is between 0 et 180 degrees, except if the MBR can not be defined. In that last case, the value -2.0 is returned.

Parameters:
polygon - polygon to process
Returns:
the orientation in degrees, -2.0 if the MBR can not be defined

isCircle

public static boolean isCircle(Polygon polygon,
                               double iMillerThreshold)
Compute if a Polygon has a circular shape or not, based on the compactedness index or Miller's index (if Miller's index equals 1, it means that the shape is a perfect circle).

Parameters:
polygon - polygon to process
iMillerThreshold - minimum threshold for Miller's index
Returns:
true if the polygon shape is a circle, otherwise false

isRectangle

public static double isRectangle(Polygon polygon,
                                 double sdConvexHullThreshold,
                                 double sdMBRThreshold)
Compute if a Polygon has a rectangular shape or not, based on the comparison with two shapes: the shape of the minimum bounding rectangle of the Polygon, and the shape of the convex hull associated to the Polygon. This comparison is computed thanks to two thresholds (threshold of maximums), one for each associated shape. If the shape is rectangular, the orientation (in degrees) based on the is returned; otherwise, the value of -1.0 is returned. Finally, if the returned value equals -2.0, it means that the MBR can not be computed.

Parameters:
polygon - polygon to process
sdConvexHullThreshold - maximum threshold for surface distance between the polygon and its convex hull
sdMBRThreshold - maximum threshold for surface distance between the polygon and its associated minimum bounding rectangle
Returns:
the orientation in degrees of the polygon, based on the orientation of the associated minimum bounding rectangle, -1.0 if the polygon shape is not defined as a retangle, and -2.0 if the MBR can not be computed

isRectangle

public static double isRectangle(double sdConvexHull,
                                 double sdConvexHullThreshold,
                                 double sdMBR,
                                 double sdMBRThreshold,
                                 Polygon mbr)
Compute if a Polygon has a rectangular shape or not, based on the comparison with two shapes: the shape of the minimum bounding rectangle of the Polygon, and the shape of the convex hull associated to the Polygon. This comparison is computed thanks to two thresholds (threshold of maximums), one for each associated shape. If the shape is rectangular, the orientation (in degrees) based on the is returned; otherwise, the value of -1.0 is returned. Finally, if the returned value equals -2.0, it means that the MBR can not be computed.

Parameters:
sdConvexHull - surface distance between the considered polygon and its convex hull
sdConvexHullThreshold - maximum threshold for surface distance between the considered polygon and its convex hull
sdMBR - surface distance between the considered polygon and its associated minimum bounding rectangle
sdMBRThreshold - maximum threshold for surface distance between the considered polygon and its associated minimum bounding rectangle
mbr - minimum bounding rectangle associated to the considered polygon
Returns:
orientation in degrees of the polygon, based on the orientation of the associated minimum bounding rectangle, -1.0 if the polygon shape is not defined as a retangle, and -2.0 if the MBR can not be computed

cleaningPolygonShape

public static Polygon cleaningPolygonShape(Polygon polygon,
                                           double threshold)
Clean a Polygon by removing the unuseful points (in regard to the chosen threshold) of a Polygon, i.e. the points which are in the alignment between the previous point and the following one. The alignment is here defined thanks to a given threshold comparatively to Pi (or 180°). The threshold has to be expressed in degrees.

Parameters:
polygon - polygon to process
threshold - threshold in degrees to remove points which are aligned with an angle of 180 +/- threshold in the polygon
Returns:
the new and cleaned polygon

cleaningMultiPolygonShape

public static MultiPolygon cleaningMultiPolygonShape(MultiPolygon multiPolygon,
                                                     double threshold)
Clean a MultiPolygon by removing the unuseful points (in regard to the chosen threshold) of a MultiPolygon, i.e. the points which are in the alignment between the previous point and the following one. The alignment is here defined thanks to a given threshold comparatively to Pi (or 180°). The threshold has to be expressed in degrees.

Parameters:
multiPolygon - multipolygon to process
threshold - threshold in degrees to remove points which are aligned with an angle of 180 +/- threshold in the multipolygon
Returns:
the new and cleaned multipolygon

cleaningPolygonShapeAutomaticThreshold

public static Polygon cleaningPolygonShapeAutomaticThreshold(Polygon polygon)
Clean a Polygon by removing the unuseful points (in regard to the chosen threshold) of a Polygon, i.e. the points which are in the alignment between the previous point and the following one. The alignment is here defined thanks to a threshold comparatively to Pi (or 180°) which is automatically computed (quasi optimal, considering a maximum area variation of 1%, comparating area variations, not the global one). The threshold has a maximum of 2 degrees. TODO: Check if the threshold matches a reality

Parameters:
polygon - polygon to clean
Returns:
the new and cleaned polygon

cleaningMultiPolygonShapeAutomaticThreshold

public static MultiPolygon cleaningMultiPolygonShapeAutomaticThreshold(MultiPolygon multiPolygon)
Clean a MultiPolygon by removing the unuseful points (in regard to the chosen threshold) of a MultiPolygon, i.e. the points which are in the alignment between the previous point and the following one. The alignment is here defined thanks to a threshold comparatively to Pi (or 180°) which is automatically computed (quasi optimal, considering a maximum area variation of 1%, comparating area variations, not the global one). The threshold has a maximum of 2 degrees. TODO: Check if the threshold matches a reality

Parameters:
multiPolygon - multipolygon to clean
Returns:
the new and cleaned multipolygon

MorphAL 0.1