Java Code Examples for org.locationtech.jts.geom.Polygon#getInteriorRingN()

The following examples show how to use org.locationtech.jts.geom.Polygon#getInteriorRingN() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeometryUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates simple arrow polygons in the direction of the coordinates.
 * 
 * @param geometries the geometries (lines and polygons) for which to create the arrows.
 * @return the list of polygon arrows.
 */
public static List<Polygon> createSimpleDirectionArrow( Geometry... geometries ) {
    List<Polygon> polygons = new ArrayList<>();
    for( Geometry geometry : geometries ) {
        for( int i = 0; i < geometry.getNumGeometries(); i++ ) {
            Geometry geometryN = geometry.getGeometryN(i);
            if (geometryN instanceof LineString) {
                LineString line = (LineString) geometryN;
                polygons.addAll(makeArrows(line));
            } else if (geometryN instanceof Polygon) {
                Polygon polygonGeom = (Polygon) geometryN;
                LineString exteriorRing = polygonGeom.getExteriorRing();
                polygons.addAll(makeArrows(exteriorRing));
                int numInteriorRing = polygonGeom.getNumInteriorRing();
                for( int j = 0; j < numInteriorRing; j++ ) {
                    LineString interiorRingN = polygonGeom.getInteriorRingN(j);
                    polygons.addAll(makeArrows(interiorRingN));
                }
            }
        }
    }
    return polygons;
}
 
Example 2
Source File: MultiPolygonUtils.java    From geofence with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the number of points of a polygon in the format
 * E+I0+I1+...+In
 * where E is the number of points of the exterior ring and I0..In are
 * the number of points of the Internal rings.
 */
public static String getPoints(final Polygon p)
{
    final StringBuilder sb = new StringBuilder();
    sb.append(p.getExteriorRing().getNumPoints());
    for (int i = 0; i < p.getNumInteriorRing(); i++)
    {
        LineString ir = p.getInteriorRingN(i);
        sb.append('+').append(ir.getNumPoints());
    }

    return sb.toString();
}
 
Example 3
Source File: JtsLineStringIterable.java    From geogson with Apache License 2.0 5 votes vote down vote up
public static JtsLineStringIterable forHolesOf(final Polygon src) {
    return new JtsLineStringIterable(new LineStringProvider() {
        @Override
        public int getNumLineStrings() {
            return src.getNumInteriorRing();
        }

        @Override
        public LineString getLineStringN(int n) {
            return src.getInteriorRingN(n);
        }
    });
}
 
Example 4
Source File: GmlEncoderv321.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a XML Polygon from a SOS Polygon.
 *
 * @param jtsPolygon
 *            SOS Polygon
 * @param xbPolType
 *            XML Polygon
 */
private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) {
    List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon);
    String srsName = getSrsName(jtsPolygon);

    for (int i = 0; i < jtsPolygons.size(); i++) {

        Polygon pol = (Polygon) jtsPolygons.get(i);

        AbstractRingPropertyType xbArpt = xbPolType.addNewExterior();
        AbstractRingType xbArt = xbArpt.addNewAbstractRing();

        LinearRingType xbLrt = LinearRingType.Factory.newInstance();

        // Exterior ring
        LineString ring = pol.getExteriorRing();
        DirectPositionListType xbPosList = xbLrt.addNewPosList();

        xbPosList.setSrsName(srsName);
        xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
        xbArt.set(xbLrt);

        // Rename element name for output
        XmlCursor cursor = xbArpt.newCursor();
        if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) {
            cursor.setName(GmlConstants.QN_LINEAR_RING_32);
        }
        cursor.dispose();

        // Interior ring
        int numberOfInteriorRings = pol.getNumInteriorRing();
        for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) {
            xbArpt = xbPolType.addNewInterior();
            xbArt = xbArpt.addNewAbstractRing();

            xbLrt = LinearRingType.Factory.newInstance();

            ring = pol.getInteriorRingN(ringNumber);

            xbPosList = xbLrt.addNewPosList();
            xbPosList.setSrsName(srsName);
            xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
            xbArt.set(xbLrt);

            // Rename element name for output
            cursor = xbArpt.newCursor();
            if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) {
                cursor.setName(GmlConstants.QN_LINEAR_RING_32);
            }
            cursor.dispose();
        }
    }
}
 
Example 5
Source File: GmlEncoderv311.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a XML Polygon from a SOS Polygon.
 *
 * @param jtsPolygon
 *            SOS Polygon
 * @param xbPolType
 *            XML Polygon
 */
private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) {
    List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon);
    for (int i = 0; i < jtsPolygons.size(); i++) {

        Polygon pol = (Polygon) jtsPolygons.get(i);

        AbstractRingPropertyType xbArpt = xbPolType.addNewExterior();
        AbstractRingType xbArt = xbArpt.addNewRing();

        LinearRingType xbLrt = LinearRingType.Factory.newInstance(getXmlOptions());

        // Exterior ring
        LineString ring = pol.getExteriorRing();
        String coords = JTSHelper.getCoordinatesString(ring);
        DirectPositionListType xbPosList = xbLrt.addNewPosList();
        xbPosList.setSrsName(getSrsName(jtsPolygon));
        // switch coordinates
        xbPosList.setStringValue(coords);
        xbArt.set(xbLrt);

        // Rename element name for output
        XmlCursor cursor = xbArpt.newCursor();
        if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING)) {
            cursor.setName(GmlConstants.QN_LINEAR_RING);
        }
        cursor.dispose();

        // Interior ring
        int numberOfInteriorRings = pol.getNumInteriorRing();
        for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) {
            xbArpt = xbPolType.addNewInterior();
            xbArt = xbArpt.addNewRing();

            xbLrt = LinearRingType.Factory.newInstance(getXmlOptions());

            ring = pol.getInteriorRingN(ringNumber);

            xbPosList = xbLrt.addNewPosList();
            xbPosList.setSrsName(getSrsName(jtsPolygon));
            xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
            xbArt.set(xbLrt);

            // Rename element name for output
            cursor = xbArpt.newCursor();
            if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING)) {
                cursor.setName(GmlConstants.QN_LINEAR_RING);
            }
            cursor.dispose();
        }
    }
}