Revision 45762 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/util/JTSUtils.java
JTSUtils.java | ||
---|---|---|
46 | 46 |
import org.slf4j.LoggerFactory; |
47 | 47 |
|
48 | 48 |
import org.gvsig.fmap.geom.Geometry; |
49 |
import static org.gvsig.fmap.geom.Geometry.JOIN_STYLE_BEVEL; |
|
50 |
import static org.gvsig.fmap.geom.Geometry.JOIN_STYLE_MITRE; |
|
51 |
import static org.gvsig.fmap.geom.Geometry.JOIN_STYLE_ROUND; |
|
49 | 52 |
import org.gvsig.fmap.geom.GeometryException; |
50 | 53 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
51 | 54 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
... | ... | |
554 | 557 |
bufParams.setJoinStyle(BufferParameters.CAP_ROUND); |
555 | 558 |
return bufParams; |
556 | 559 |
} |
560 |
|
|
561 |
public static BufferParameters getBufferParameters(int joinStyle, int endCapStyle){ |
|
562 |
BufferParameters bufParams = new BufferParameters(); |
|
563 |
bufParams.setSingleSided(true); |
|
564 |
bufParams.setEndCapStyle(endCapStyle); |
|
565 |
bufParams.setJoinStyle(joinStyle); |
|
566 |
bufParams.setQuadrantSegments(calculateQuadrantSegments(joinStyle)); |
|
567 |
return bufParams; |
|
568 |
} |
|
569 |
|
|
570 |
public static int calculateQuadrantSegments(int joinStyle) throws IllegalArgumentException { |
|
571 |
int quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS; |
|
572 |
switch(joinStyle){ |
|
573 |
case JOIN_STYLE_ROUND: |
|
574 |
quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS; |
|
575 |
break; |
|
576 |
case JOIN_STYLE_MITRE: |
|
577 |
quadrantSegments = - (int) BufferParameters.DEFAULT_MITRE_LIMIT; |
|
578 |
break; |
|
579 |
case JOIN_STYLE_BEVEL: |
|
580 |
quadrantSegments = 0; |
|
581 |
break; |
|
582 |
default: |
|
583 |
throw new IllegalArgumentException("Invalid jointStyle "+joinStyle); |
|
584 |
} |
|
585 |
return quadrantSegments; |
|
586 |
} |
|
557 | 587 |
|
558 |
|
|
559 | 588 |
/** |
560 | 589 |
* Creates a offset from a closed line at a distance |
561 | 590 |
* |
591 |
* @param proj |
|
592 |
* @param coordinates |
|
562 | 593 |
* @param distance |
563 | 594 |
* @return |
564 | 595 |
*/ |
565 | 596 |
public static Geometry offsetClosedLine(IProjection proj, ArrayListCoordinateSequence coordinates, double distance) { |
566 | 597 |
com.vividsolutions.jts.geom.Geometry jtsGeom = JTSUtils.createJTSPolygon(coordinates); |
567 | 598 |
com.vividsolutions.jts.geom.Geometry geomJTS = jtsGeom.buffer(distance); |
599 |
return jtsPolygonToJtsMultiLineString(geomJTS, proj); |
|
600 |
} |
|
601 |
|
|
602 |
/** |
|
603 |
* Creates a offset from a closed line at a distance |
|
604 |
* |
|
605 |
* @param proj |
|
606 |
* @param coordinates |
|
607 |
* @param joinStyle |
|
608 |
* @param distance |
|
609 |
* @return |
|
610 |
*/ |
|
611 |
public static Geometry offsetClosedLine(IProjection proj, ArrayListCoordinateSequence coordinates, int joinStyle, double distance) { |
|
612 |
com.vividsolutions.jts.geom.Geometry jtsGeom = JTSUtils.createJTSPolygon(coordinates); |
|
613 |
com.vividsolutions.jts.geom.Geometry geomJTS = jtsGeom.buffer(distance, calculateQuadrantSegments(joinStyle), BufferParameters.CAP_FLAT); |
|
614 |
return jtsPolygonToJtsMultiLineString(geomJTS, proj); |
|
615 |
} |
|
616 |
|
|
617 |
protected static Geometry jtsPolygonToJtsMultiLineString(com.vividsolutions.jts.geom.Geometry geomJTS, IProjection proj) { |
|
568 | 618 |
if (geomJTS instanceof com.vividsolutions.jts.geom.Polygon) { |
569 | 619 |
com.vividsolutions.jts.geom.Polygon polygonJTS = (com.vividsolutions.jts.geom.Polygon) geomJTS; |
570 | 620 |
LineString shell = polygonJTS.getExteriorRing(); |
... | ... | |
581 | 631 |
return JTSUtils.createGeometry(proj, shell); |
582 | 632 |
} else if (geomJTS instanceof com.vividsolutions.jts.geom.MultiPolygon) { |
583 | 633 |
MultiPolygon multiPolygonJTS = (com.vividsolutions.jts.geom.MultiPolygon) geomJTS; |
584 |
List<LineString> lineStringList = new ArrayList<LineString>();
|
|
634 |
List<LineString> lineStringList = new ArrayList<>(); |
|
585 | 635 |
for (int i = 0; i < multiPolygonJTS.getNumGeometries(); i++) { |
586 | 636 |
com.vividsolutions.jts.geom.Polygon polygonJTS = |
587 |
(com.vividsolutions.jts.geom.Polygon) multiPolygonJTS.getGeometryN(i); |
|
637 |
(com.vividsolutions.jts.geom.Polygon) multiPolygonJTS.getGeometryN(i);
|
|
588 | 638 |
lineStringList.add(polygonJTS.getExteriorRing()); |
589 | 639 |
int numHoles = polygonJTS.getNumInteriorRing(); |
590 | 640 |
if (numHoles > 0) { |
Also available in: Unified diff