Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public static Geometry getGeometryN(Geometry g, int i)
public static Geometry getPolygonShell(Geometry g)
{
if (g instanceof Polygon) {
LinearRing shell = (LinearRing) ((Polygon) g).getExteriorRing();
LinearRing shell = ((Polygon) g).getExteriorRing();
return g.getFactory().createPolygon(shell, null);
}
if (g instanceof MultiPolygon) {
Polygon[] poly = new Polygon[g.getNumGeometries()];
for (int i = 0; i < g.getNumGeometries(); i++) {
LinearRing shell = (LinearRing) ((Polygon) g.getGeometryN(i)).getExteriorRing();
LinearRing shell = ((Polygon) g.getGeometryN(i)).getExteriorRing();
poly[i] = g.getFactory().createPolygon(shell, null);
}
return g.getFactory().createMultiPolygon(poly);
Expand All @@ -82,7 +82,7 @@ public void filter(Geometry geom) {
if (geom instanceof Polygon) {
Polygon poly = (Polygon) geom;
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
Polygon hole = geom.getFactory().createPolygon((LinearRing) poly.getInteriorRingN(i), null);
Polygon hole = geom.getFactory().createPolygon(poly.getInteriorRingN(i), null);
holePolys.add(hole);
}
}
Expand All @@ -94,7 +94,7 @@ public void filter(Geometry geom) {
public static Geometry getPolygonHoleN(Geometry g, int i)
{
if (g instanceof Polygon) {
LinearRing ring = (LinearRing) ((Polygon) g).getInteriorRingN(i);
LinearRing ring = ((Polygon) g).getInteriorRingN(i);
return ring;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public Polygon addHole(Polygon poly, LinearRing hole)
int nOrigHoles = poly.getNumInteriorRing();
LinearRing[] newHoles = new LinearRing[nOrigHoles + 1];
for (int i = 0; i < nOrigHoles; i++) {
newHoles[i] = (LinearRing) poly.getInteriorRingN(i);
newHoles[i] = poly.getInteriorRingN(i);
}
newHoles[nOrigHoles] = hole;
return geomFactory.createPolygon((LinearRing) poly.getExteriorRing(), newHoles);
return geomFactory.createPolygon(poly.getExteriorRing(), newHoles);
}

public Geometry combine(Geometry orig, Geometry geom)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ private int locateInPolygon(Coordinate p, Polygon poly)
{
if (poly.isEmpty()) return Location.EXTERIOR;

LinearRing shell = (LinearRing) poly.getExteriorRing();
LinearRing shell = poly.getExteriorRing();

int shellLoc = locateInPolygonRing(p, shell);
if (shellLoc == Location.EXTERIOR) return Location.EXTERIOR;
if (shellLoc == Location.BOUNDARY) return Location.BOUNDARY;
// now test if the point lies in or on the holes
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
LinearRing hole = (LinearRing) poly.getInteriorRingN(i);
LinearRing hole = poly.getInteriorRingN(i);
int holeLoc = locateInPolygonRing(p, hole);
if (holeLoc == Location.INTERIOR) return Location.EXTERIOR;
if (holeLoc == Location.BOUNDARY) return Location.BOUNDARY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ else if (geom instanceof GeometryCollection) {
public static int locatePointInPolygon(Coordinate p, Polygon poly)
{
if (poly.isEmpty()) return Location.EXTERIOR;
LinearRing shell = (LinearRing) poly.getExteriorRing();
LinearRing shell = poly.getExteriorRing();
int shellLoc = locatePointInRing(p, shell);
if (shellLoc != Location.INTERIOR) return shellLoc;

// now test if the point lies in or on the holes
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
LinearRing hole = (LinearRing) poly.getInteriorRingN(i);
LinearRing hole = poly.getInteriorRingN(i);
int holeLoc = locatePointInRing(p, hole);
if (holeLoc == Location.BOUNDARY) return Location.BOUNDARY;
if (holeLoc == Location.INTERIOR) return Location.EXTERIOR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ public boolean isRectangle()
return true;
}

public LineString getExteriorRing() {
public LinearRing getExteriorRing() {
return shell;
}

public int getNumInteriorRing() {
return holes.length;
}

public LineString getInteriorRingN(int n) {
public LinearRing getInteriorRingN(int n) {
return holes[n];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ protected Geometry transformMultiLineString(MultiLineString geom, Geometry paren

protected Geometry transformPolygon(Polygon geom, Geometry parent) {
boolean isAllValidLinearRings = true;
Geometry shell = transformLinearRing((LinearRing) geom.getExteriorRing(), geom);
Geometry shell = transformLinearRing(geom.getExteriorRing(), geom);

if (shell == null
|| ! (shell instanceof LinearRing)
Expand All @@ -249,7 +249,7 @@ protected Geometry transformPolygon(Polygon geom, Geometry parent) {

ArrayList holes = new ArrayList();
for (int i = 0; i < geom.getNumInteriorRing(); i++) {
Geometry hole = transformLinearRing((LinearRing) geom.getInteriorRingN(i), geom);
Geometry hole = transformLinearRing(geom.getInteriorRingN(i), geom);
if (hole == null || hole.isEmpty()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ private void addPolygonRing(LinearRing lr, int cwLeft, int cwRight)
private void addPolygon(Polygon p)
{
addPolygonRing(
(LinearRing) p.getExteriorRing(),
p.getExteriorRing(),
Location.EXTERIOR,
Location.INTERIOR);

for (int i = 0; i < p.getNumInteriorRing(); i++) {
LinearRing hole = (LinearRing) p.getInteriorRingN(i);
LinearRing hole = p.getInteriorRingN(i);

// Holes are topologically labelled opposite to the shell, since
// the interior of the polygon lies on their opposite side
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private void writePolygon(Polygon p, Writer writer, int level)
startLine(level + 1, writer);
startGeomTag(GMLConstants.GML_OUTER_BOUNDARY_IS, null, writer);

writeLinearRing((LinearRing) p.getExteriorRing(), writer, level + 2);
writeLinearRing(p.getExteriorRing(), writer, level + 2);

startLine(level + 1, writer);
endGeomTag(GMLConstants.GML_OUTER_BOUNDARY_IS, writer);
Expand All @@ -279,7 +279,7 @@ private void writePolygon(Polygon p, Writer writer, int level)
startLine(level + 1, writer);
startGeomTag(GMLConstants.GML_INNER_BOUNDARY_IS, null, writer);

writeLinearRing((LinearRing) p.getInteriorRingN(t), writer, level + 2);
writeLinearRing(p.getInteriorRingN(t), writer, level + 2);

startLine(level + 1, writer);
endGeomTag(GMLConstants.GML_INNER_BOUNDARY_IS, writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ private void writePolygon(Polygon p, String attributes, int level,
writeModifiers(level, buf);

startLine(" <outerBoundaryIs>\n", level, buf);
writeLinearRing((LinearRing) p.getExteriorRing(), null, false, level + 1, buf);
writeLinearRing(p.getExteriorRing(), null, false, level + 1, buf);
startLine(" </outerBoundaryIs>\n", level, buf);

for (int t = 0; t < p.getNumInteriorRing(); t++) {
startLine(" <innerBoundaryIs>\n", level, buf);
writeLinearRing((LinearRing) p.getInteriorRingN(t), null, false, level + 1, buf);
writeLinearRing(p.getInteriorRingN(t), null, false, level + 1, buf);
startLine(" </innerBoundaryIs>\n", level, buf);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void addPolygon(Polygon p)
offsetSide = Position.RIGHT;
}

LinearRing shell = (LinearRing) p.getExteriorRing();
LinearRing shell = p.getExteriorRing();
Coordinate[] shellCoord = CoordinateArrays.removeRepeatedPoints(shell.getCoordinates());
// optimization - don't bother computing buffer
// if the polygon would be completely eroded
Expand All @@ -175,7 +175,7 @@ private void addPolygon(Polygon p)

for (int i = 0; i < p.getNumInteriorRing(); i++) {

LinearRing hole = (LinearRing) p.getInteriorRingN(i);
LinearRing hole = p.getInteriorRingN(i);
Coordinate[] holeCoord = CoordinateArrays.removeRepeatedPoints(hole.getCoordinates());

// optimization - don't bother computing buffer for this hole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ private void checkInvalidCoordinates(Polygon poly)

private void checkClosedRings(Polygon poly)
{
checkClosedRing((LinearRing) poly.getExteriorRing());
checkClosedRing(poly.getExteriorRing());
if (validErr != null) return;
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
checkClosedRing((LinearRing) poly.getInteriorRingN(i));
checkClosedRing(poly.getInteriorRingN(i));
if (validErr != null) return;
}
}
Expand Down Expand Up @@ -439,7 +439,7 @@ private void checkNoSelfIntersectingRing(EdgeIntersectionList eiList)
*/
private void checkHolesInShell(Polygon p, GeometryGraph graph)
{
LinearRing shell = (LinearRing) p.getExteriorRing();
LinearRing shell = p.getExteriorRing();

//PointInRing pir = new SimplePointInRing(shell);
//PointInRing pir = new SIRtreePointInRing(shell);
Expand All @@ -448,7 +448,7 @@ private void checkHolesInShell(Polygon p, GeometryGraph graph)

for (int i = 0; i < p.getNumInteriorRing(); i++) {

LinearRing hole = (LinearRing) p.getInteriorRingN(i);
LinearRing hole = p.getInteriorRingN(i);
Coordinate holePt = findPtNotNode(hole.getCoordinates(), shell, graph);
/**
* If no non-node hole vertex can be found, the hole must
Expand Down Expand Up @@ -486,7 +486,7 @@ private void checkHolesNotNested(Polygon p, GeometryGraph graph)
//SweeplineNestedRingTester nestedTester = new SweeplineNestedRingTester(arg[0]);

for (int i = 0; i < p.getNumInteriorRing(); i++) {
LinearRing innerHole = (LinearRing) p.getInteriorRingN(i);
LinearRing innerHole = p.getInteriorRingN(i);
nestedTester.add(innerHole);
}
boolean isNonNested = nestedTester.isNonNested();
Expand All @@ -513,7 +513,7 @@ private void checkShellsNotNested(MultiPolygon mp, GeometryGraph graph)
{
for (int i = 0; i < mp.getNumGeometries(); i++) {
Polygon p = (Polygon) mp.getGeometryN(i);
LinearRing shell = (LinearRing) p.getExteriorRing();
LinearRing shell = p.getExteriorRing();
for (int j = 0; j < mp.getNumGeometries(); j++) {
if (i == j) continue;
Polygon p2 = (Polygon) mp.getGeometryN(j);
Expand All @@ -536,7 +536,7 @@ private void checkShellNotNested(LinearRing shell, Polygon p, GeometryGraph grap
{
Coordinate[] shellPts = shell.getCoordinates();
// test if shell is inside polygon shell
LinearRing polyShell = (LinearRing) p.getExteriorRing();
LinearRing polyShell = p.getExteriorRing();
Coordinate[] polyPts = polyShell.getCoordinates();
Coordinate shellPt = findPtNotNode(shellPts, polyShell, graph);
// if no point could be found, we can assume that the shell is outside the polygon
Expand All @@ -561,7 +561,7 @@ private void checkShellNotNested(LinearRing shell, Polygon p, GeometryGraph grap
*/
Coordinate badNestedPt = null;
for (int i = 0; i < p.getNumInteriorRing(); i++) {
LinearRing hole = (LinearRing) p.getInteriorRingN(i);
LinearRing hole = p.getInteriorRingN(i);
badNestedPt = checkShellInsideHole(shell, hole, graph);
if (badNestedPt == null)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Geometry getGeometry()
LineSegment baseLine = getSquareBaseLine();
Coordinate origin = baseLine.getCoordinate(0);
LinearRing[] holes = getHoles(level, origin.x, origin.y, getDiameter());
LinearRing shell = (LinearRing) ((Polygon) geomFactory.toGeometry(getSquareExtent())).getExteriorRing();
LinearRing shell = ((Polygon) geomFactory.toGeometry(getSquareExtent())).getExteriorRing();
return geomFactory.createPolygon(
shell, holes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ public void testGoodLinearRing()
public void testBadPolygonShell()
{
Polygon poly = (Polygon) fromWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
updateNonClosedRing((LinearRing) poly.getExteriorRing());
updateNonClosedRing(poly.getExteriorRing());
checkIsValid(poly, false);
}

public void testBadPolygonHole()
{
Polygon poly = (Polygon) fromWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1) ))");
updateNonClosedRing((LinearRing) poly.getInteriorRingN(0));
updateNonClosedRing(poly.getInteriorRingN(0));
checkIsValid(poly, false);
}

Expand All @@ -79,7 +79,7 @@ public void testBadGeometryCollection()
{
GeometryCollection gc = (GeometryCollection) fromWKT("GEOMETRYCOLLECTION ( POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1) )), POINT(0 0) )");
Polygon poly = (Polygon) gc.getGeometryN(0);
updateNonClosedRing((LinearRing) poly.getInteriorRingN(0));
updateNonClosedRing(poly.getInteriorRingN(0));
checkIsValid(poly, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public PolygonHoleRemover(Polygon poly, Predicate isRemoved) {
public Polygon getResult()
{
GeometryFactory gf = poly.getFactory();
Polygon shell = gf.createPolygon((LinearRing) poly.getExteriorRing());
Polygon shell = gf.createPolygon(poly.getExteriorRing());

List holes = new ArrayList();
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
LinearRing hole = (LinearRing) poly.getInteriorRingN(i);
LinearRing hole = poly.getInteriorRingN(i);
if (! isRemoved.value(hole)) {
holes.add(hole);
}
Expand All @@ -96,7 +96,7 @@ public Polygon getResult()
return poly;

// return new polygon with covered holes only
Polygon result = gf.createPolygon((LinearRing) poly.getExteriorRing(),
Polygon result = gf.createPolygon(poly.getExteriorRing(),
GeometryFactory.toLinearRingArray(holes));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ public PolygonInvalidHoleRemover(Polygon poly) {
public Polygon getResult()
{
GeometryFactory gf = poly.getFactory();
Polygon shell = gf.createPolygon((LinearRing) poly.getExteriorRing());
Polygon shell = gf.createPolygon(poly.getExteriorRing());
PreparedGeometry shellPrep = PreparedGeometryFactory.prepare(shell);

List holes = new ArrayList();
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
LinearRing hole = (LinearRing) poly.getInteriorRingN(i);
LinearRing hole = poly.getInteriorRingN(i);
if (shellPrep.covers(hole)) {
holes.add(hole);
}
Expand All @@ -110,7 +110,7 @@ public Polygon getResult()
return poly;

// return new polygon with covered holes only
Polygon result = gf.createPolygon((LinearRing) poly.getExteriorRing(),
Polygon result = gf.createPolygon(poly.getExteriorRing(),
GeometryFactory.toLinearRingArray(holes));
return result;
}
Expand Down