| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
package org.locationtech.jts.geom; |
| 15 |
|
| 16 |
import java.util.ArrayList; |
| 17 |
|
| 18 |
/** |
| 19 |
* Models a collection of {@link Polygon}s. |
| 20 |
* <p> |
| 21 |
* As per the OGC SFS specification, |
| 22 |
* the Polygons in a MultiPolygon may not overlap, |
| 23 |
* and may only touch at single points. |
| 24 |
* This allows the topological point-set semantics |
| 25 |
* to be well-defined. |
| 26 |
* |
| 27 |
* |
| 28 |
*@version 1.7 |
| 29 |
*/ |
| 30 |
public class MultiPolygon |
| 31 |
extends GeometryCollection |
| 32 |
implements Polygonal |
| 33 |
{ |
| 34 |
private static final long serialVersionUID = -551033529766975875L; |
| 35 |
/** |
| 36 |
* Constructs a <code>MultiPolygon</code>. |
| 37 |
* |
| 38 |
*@param polygons the <code>Polygon</code>s for this <code>MultiPolygon</code> |
| 39 |
* , or <code>null</code> or an empty array to create the empty geometry. |
| 40 |
* Elements may be empty <code>Polygon</code>s, but not <code>null</code> |
| 41 |
* s. The polygons must conform to the assertions specified in the <A |
| 42 |
* HREF="http://www.opengis.org/techno/specs.htm">OpenGIS Simple Features |
| 43 |
* Specification for SQL</A> . |
| 44 |
*@param precisionModel the specification of the grid of allowable points |
| 45 |
* for this <code>MultiPolygon</code> |
| 46 |
*@param SRID the ID of the Spatial Reference System used by this |
| 47 |
* <code>MultiPolygon</code> |
| 48 |
* @deprecated Use GeometryFactory instead |
| 49 |
*/ |
| 50 |
public MultiPolygon(Polygon[] polygons, PrecisionModel precisionModel, int SRID) { |
| 51 |
this(polygons, new GeometryFactory(precisionModel, SRID)); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
/** |
| 56 |
* @param polygons |
| 57 |
* the <code>Polygon</code>s for this <code>MultiPolygon</code>, |
| 58 |
* or <code>null</code> or an empty array to create the empty |
| 59 |
* geometry. Elements may be empty <code>Polygon</code>s, but |
| 60 |
* not <code>null</code>s. The polygons must conform to the |
| 61 |
* assertions specified in the <A |
| 62 |
* HREF="http://www.opengis.org/techno/specs.htm">OpenGIS Simple |
| 63 |
* Features Specification for SQL</A>. |
| 64 |
*/ |
| 65 |
public MultiPolygon(Polygon[] polygons, GeometryFactory factory) { |
| 66 |
super(polygons, factory); |
| 67 |
} |
| 68 |
|
| 69 |
public int getDimension() { |
| 70 |
return 2; |
| 71 |
} |
| 72 |
|
| 73 |
public int getBoundaryDimension() { |
| 74 |
return 1; |
| 75 |
} |
| 76 |
|
| 77 |
public String getGeometryType() { |
| 78 |
return Geometry.TYPENAME_MULTIPOLYGON; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
/** |
| 88 |
* Computes the boundary of this geometry |
| 89 |
* |
| 90 |
* @return a lineal geometry (which may be empty) |
| 91 |
* @see Geometry#getBoundary |
| 92 |
*/ |
| 93 |
public Geometry getBoundary() { |
| 94 |
if (isEmpty()) { |
| 95 |
return getFactory().createMultiLineString(); |
| 96 |
} |
| 97 |
ArrayList allRings = new ArrayList(); |
| 98 |
for (int i = 0; i < geometries.length; i++) { |
| 99 |
Polygon polygon = (Polygon) geometries[i]; |
| 100 |
Geometry rings = polygon.getBoundary(); |
| 101 |
for (int j = 0; j < rings.getNumGeometries(); j++) { |
| 102 |
allRings.add(rings.getGeometryN(j)); |
| 103 |
} |
| 104 |
} |
| 105 |
LineString[] allRingsArray = new LineString[allRings.size()]; |
| 106 |
return getFactory().createMultiLineString((LineString[]) allRings.toArray(allRingsArray)); |
| 107 |
} |
| 108 |
|
| 109 |
public boolean equalsExact(Geometry other, double tolerance) { |
| 110 |
if (!isEquivalentClass(other)) { |
| 111 |
return false; |
| 112 |
} |
| 113 |
return super.equalsExact(other, tolerance); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Creates a {@link MultiPolygon} with |
| 118 |
* every component reversed. |
| 119 |
* The order of the components in the collection are not reversed. |
| 120 |
* |
| 121 |
* @return a MultiPolygon in the reverse order |
| 122 |
*/ |
| 123 |
public MultiPolygon reverse() { |
| 124 |
return (MultiPolygon) super.reverse(); |
| 125 |
} |
| 126 |
|
| 127 |
protected MultiPolygon copyInternal() { |
| 128 |
Polygon[] polygons = new Polygon[this.geometries.length]; |
| 129 |
for (int i = 0; i < polygons.length; i++) { |
| 130 |
polygons[i] = (Polygon) this.geometries[i].copy(); |
| 131 |
} |
| 132 |
return new MultiPolygon(polygons, factory); |
| 133 |
} |
| 134 |
|
| 135 |
protected int getTypeCode() { |
| 136 |
return Geometry.TYPECODE_MULTIPOLYGON; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|