Package dev.avelar.mapnik
Class Geometry
java.lang.Object
dev.avelar.mapnik.Geometry
- Direct Known Subclasses:
Geometry.Collection,Geometry.LineString,Geometry.MultiLineString,Geometry.MultiPoint,Geometry.MultiPolygon,Geometry.Point,Geometry.Polygon
A 2D geometry: a point, line, polygon, a multi version of those, or a collection. Geometries are
immutable and hold no native memory. Build them with the factories (
point(double, double), polygon(double[], double[]...)
and so on) or read them from WKT, WKB or GeoJSON, and write them back out in any of the three.
Coordinates are plain numbers in whatever projection your data uses. Only 2D is supported: a third value in GeoJSON is ignored, and WKT or WKB with Z or M is rejected.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA mix of geometries.static final classA connected series of points.static final classSeveral lines.static final classSeveral separate points.static final classSeveral polygons.static final classThe closest point on a geometry to some location, and how far away it is.static final classA single location.static final classAn area: an exterior ring and any number of holes. -
Method Summary
Modifier and TypeMethodDescriptioncentroid()The centre of mass.closestPoint(double x, double y) The point of this geometry nearest to (x, y), with its distance.static Geometry.Collectioncollection(Geometry... geometries) A copy with polygon rings wound consistently: exteriors counter-clockwise, holes clockwise.static Geometry.Collectionempty()A geometry with nothing in it: an empty collection.envelope()The bounding box, or null if the geometry is empty.booleanstatic GeometryfromGeoJson(String json) Read a GeoJSON geometry object.static GeometryfromWkb(byte[] data) Read 2D WKB of either byte order.static GeometryRead WKT, such asPOINT(1 2)orPOLYGON((0 0,1 0,1 1,0 0)).inthashCode()A point that lies inside a polygon, as far from its edges as reasonably possible (a good place for a label, unlike the centroid of a C shape).abstract booleanisEmpty()True if it has no coordinates, for example an empty collection.booleanisSimple()True if the geometry has no self-intersections or repeated points that make it complex.booleanisValid()True if the geometry is valid: rings do not cross themselves, holes lie inside the exterior and do not overlap each other, and so on.abstract GeometryKindkind()What kind of geometry this is.static Geometry.LineStringlineString(double... xy) A line through the points given as x0, y0, x1, y1, ...static Geometry.LineStringlineString(List<Point2d> points) static Geometry.MultiLineStringmultiLineString(Geometry.LineString... lines) static Geometry.MultiPointmultiPoint(double... xy) static Geometry.MultiPolygonmultiPolygon(Geometry.Polygon... polygons) offset(double distance) A parallel copy of a line,distanceto its left (positive) or right (negative).static Geometry.Pointpoint(double x, double y) static Geometry.Polygonpolygon(double[] exterior, double[]... holes) A polygon from an exterior ring and any holes, each given as x0, y0, x1, y1, ...static Geometry.PolygonA rectangle coveringbox.reproject(CoordinateTransform transform) A copy with every coordinate moved from the transform's source projection to its destination.simplify(SimplifyAlgorithm algorithm, double tolerance) A copy with fewer points, keeping the overall shape.As a GeoJSON geometry object, for example{"type":"Point","coordinates":[1,2]}.toString()byte[]toWkb()As little-endian 2D WKB.toWkt()As WKT, for examplePOINT(1 2).Why the geometry is invalid, in Mapnik's words, or a sentence saying it is valid.
-
Method Details
-
kind
What kind of geometry this is. -
isEmpty
public abstract boolean isEmpty()True if it has no coordinates, for example an empty collection. -
envelope
The bounding box, or null if the geometry is empty. -
toWkt
As WKT, for examplePOINT(1 2). -
toGeoJson
As a GeoJSON geometry object, for example{"type":"Point","coordinates":[1,2]}. -
toWkb
public byte[] toWkb()As little-endian 2D WKB. -
equals
-
hashCode
public int hashCode() -
toString
-
centroid
The centre of mass. ThrowsMapnikExceptionfor an empty geometry. -
interiorPoint
A point that lies inside a polygon, as far from its edges as reasonably possible (a good place for a label, unlike the centroid of a C shape). For a multi polygon it uses the polygon with the largest bounding box. ThrowsIllegalStateExceptionfor other kinds. -
closestPoint
The point of this geometry nearest to (x, y), with its distance. ThrowsMapnikExceptionif empty. -
isValid
public boolean isValid()True if the geometry is valid: rings do not cross themselves, holes lie inside the exterior and do not overlap each other, and so on. For a ring that crosses itself Mapnik reports the problem as a wrong orientation, because a crossing ring has no single winding. -
validityReason
Why the geometry is invalid, in Mapnik's words, or a sentence saying it is valid. -
isSimple
public boolean isSimple()True if the geometry has no self-intersections or repeated points that make it complex. -
corrected
A copy with polygon rings wound consistently: exteriors counter-clockwise, holes clockwise. Either winding counts as valid for an ordinary polygon, but a consistent one is what GeoJSON and many other tools expect. It does not repair a ring that crosses itself. -
simplify
A copy with fewer points, keeping the overall shape.toleranceis in the geometry's units and means a different distance for each algorithm. Polygon rings are never collapsed to fewer than four points, and points and multi points are unchanged. -
offset
A parallel copy of a line,distanceto its left (positive) or right (negative). For line strings, multi line strings and collections of them. ThrowsMapnikExceptionfor points and polygons. -
reproject
A copy with every coordinate moved from the transform's source projection to its destination. ThrowsMapnikExceptionif any point cannot be transformed. -
point
-
lineString
A line through the points given as x0, y0, x1, y1, ... At least two points. -
lineString
-
polygon
A polygon from an exterior ring and any holes, each given as x0, y0, x1, y1, ... The rings must be closed (the last point repeats the first) and have at least four points. -
rectangle
A rectangle coveringbox. -
multiPoint
-
multiLineString
-
multiPolygon
-
collection
-
empty
A geometry with nothing in it: an empty collection. -
fromWkb
Read 2D WKB of either byte order. ThrowsIllegalArgumentExceptionif it is malformed or has Z or M. -
fromWkt
Read WKT, such asPOINT(1 2)orPOLYGON((0 0,1 0,1 1,0 0)). Type names are case-insensitive.EMPTYis accepted for the multi types, collections and lines. ThrowsIllegalArgumentExceptionwith the position of the first problem. -
fromGeoJson
Read a GeoJSON geometry object. A third (elevation) value in a position is ignored. Anullgeometry reads asempty().
-