Search in sources :

Example 21 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class DistanceOp method computeContainmentDistance.

private boolean computeContainmentDistance(final List<Point> points, final List<Polygon> polygons) {
    for (final Point point : points) {
        final double x = point.getX();
        final double y = point.getY();
        for (final Polygon polygon : polygons) {
            if (computeContainmentDistance(polygon, x, y)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon)

Example 22 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class EdgeRing method getPolygon.

/**
 * Computes the {@link Polygon} formed by this ring and any contained holes.
 *
 * @return the {@link Polygon} formed by this ring and its holes.
 */
public Polygon getPolygon() {
    final List<LinearRing> rings = new ArrayList<>();
    rings.add(this.ring);
    if (this.holes != null) {
        rings.addAll(this.holes);
    }
    final Polygon poly = this.factory.polygon(rings);
    return poly;
}
Also used : ArrayList(java.util.ArrayList) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon)

Example 23 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class Polygonizer method polygonize.

/**
 * Performs the polygonization, if it has not already been carried out.
 */
private void polygonize() {
    // check if already computed
    if (this.polygons != null) {
        return;
    }
    this.polygons = new ArrayList<>();
    // if no geometries were supplied it's possible that graph is null
    if (this.graph == null) {
        return;
    }
    this.dangles = this.graph.deleteDangles();
    this.cutEdges = this.graph.deleteCutEdges();
    final List<EdgeRing> edgeRingList = this.graph.getEdgeRings();
    // Debug.printTime("Build Edge Rings");
    List<EdgeRing> validEdgeRingList = new ArrayList<>();
    this.invalidRingLines = new ArrayList<>();
    if (this.isCheckingRingsValid) {
        findValidRings(edgeRingList, validEdgeRingList, this.invalidRingLines);
    } else {
        validEdgeRingList = edgeRingList;
    }
    // Debug.printTime("Validate Rings");
    findShellsAndHoles(validEdgeRingList);
    assignHolesToShells(this.holeList, this.shellList);
    // Debug.printTime("Assign Holes");
    this.polygons = new ArrayList<>();
    for (final EdgeRing edgeRing : this.shellList) {
        final Polygon polygon = edgeRing.getPolygon();
        this.polygons.add(polygon);
    }
}
Also used : ArrayList(java.util.ArrayList) Polygon(com.revolsys.geometry.model.Polygon)

Example 24 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class PolygonBuilder method getPolygons.

public List<Polygon> getPolygons() {
    final List<Polygon> polygons = new ArrayList<>();
    for (final EdgeRing edgeRing : this.shellList) {
        final Polygon polygon = edgeRing.toPolygon(this.geometryFactory);
        polygons.add(polygon);
    }
    return polygons;
}
Also used : EdgeRing(com.revolsys.geometry.geomgraph.EdgeRing) ArrayList(java.util.ArrayList) Polygon(com.revolsys.geometry.model.Polygon)

Example 25 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class EsriGeodatabaseXmlRecordWriter method writeDataElement.

private void writeDataElement(final RecordDefinition recordDefinition, final Geometry geometry) {
    final String dataElementType;
    final FieldDefinition geometryField = recordDefinition.getGeometryField();
    boolean hasGeometry = false;
    DataType geometryDataType = null;
    if (geometryField != null) {
        geometryDataType = geometryField.getDataType();
        if (this.fieldTypes.getFieldType(geometryDataType) != null) {
            hasGeometry = true;
            if (geometryDataType.equals(DataTypes.POINT)) {
                this.geometryType = GEOMETRY_TYPE_POINT;
            } else if (geometryDataType.equals(DataTypes.MULTI_POINT)) {
                this.geometryType = GEOMETRY_TYPE_MULTI_POINT;
            } else if (geometryDataType.equals(DataTypes.LINE_STRING)) {
                this.geometryType = GEOMETRY_TYPE_POLYLINE;
            } else if (geometryDataType.equals(DataTypes.MULTI_LINE_STRING)) {
                this.geometryType = GEOMETRY_TYPE_POLYLINE;
            } else if (geometryDataType.equals(DataTypes.POLYGON)) {
                this.geometryType = GEOMETRY_TYPE_POLYGON;
            } else {
                if (geometry instanceof Point) {
                    this.geometryType = GEOMETRY_TYPE_POINT;
                } else if (geometry instanceof Punctual) {
                    this.geometryType = GEOMETRY_TYPE_MULTI_POINT;
                } else if (geometry instanceof Lineal) {
                    this.geometryType = GEOMETRY_TYPE_POLYLINE;
                } else if (geometry instanceof Polygon) {
                    this.geometryType = GEOMETRY_TYPE_POLYGON;
                } else {
                    hasGeometry = false;
                }
            }
        }
    }
    if (hasGeometry) {
        dataElementType = DATA_ELEMENT_FEATURE_CLASS;
        this.datasetType = DATASET_TYPE_FEATURE_CLASS;
    } else {
        dataElementType = DATA_ELEMENT_TABLE;
        this.datasetType = DATASET_TYPE_TABLE;
    }
    this.out.startTag(DATA_ELEMENT);
    this.out.attribute(XsiConstants.TYPE, dataElementType);
    final String path = recordDefinition.getPath();
    final String localName = PathUtil.getName(path);
    this.out.element(CATALOG_PATH, "/FC=" + localName);
    this.out.element(NAME, localName);
    this.out.element(METADATA_RETRIEVED, true);
    this.out.startTag(METADATA);
    this.out.attribute(XsiConstants.TYPE, XML_PROPERTY_SET_TYPE);
    this.out.startTag(XML_DOC);
    this.out.text("<?xml version=\"1.0\"?>");
    this.out.text("<metadata xml:lang=\"en\">");
    this.out.text("<Esri>");
    this.out.text("<MetaID>{");
    this.out.text(UUID.randomUUID().toString().toUpperCase());
    this.out.text("}</MetaID>");
    this.out.text("<CreaDate>");
    final Timestamp date = new Timestamp(System.currentTimeMillis());
    this.out.text(Dates.format("yyyyMMdd", date));
    this.out.text("</CreaDate>");
    this.out.text("<CreaTime>");
    this.out.text(Dates.format("HHmmssSS", date));
    this.out.text("</CreaTime>");
    this.out.text("<SyncOnce>TRUE</SyncOnce>");
    this.out.text("</Esri>");
    this.out.text("</metadata>");
    this.out.endTag(XML_DOC);
    this.out.endTag(METADATA);
    this.out.element(DATASET_TYPE, this.datasetType);
    this.out.element(DSID, this.datasetId++);
    this.out.element(VERSIONED, false);
    this.out.element(CAN_VERSION, false);
    this.out.element(HAS_OID, true);
    this.out.element(OBJECT_ID_FIELD_NAME, "OBJECTID");
    writeFields(recordDefinition);
    this.out.element(CLSID, "{52353152-891A-11D0-BEC6-00805F7C4268}");
    this.out.emptyTag(EXTCLSID);
    this.out.startTag(RELATIONSHIP_CLASS_NAMES);
    this.out.attribute(XsiConstants.TYPE, NAMES_TYPE);
    this.out.endTag(RELATIONSHIP_CLASS_NAMES);
    this.out.element(ALIAS_NAME, localName);
    this.out.emptyTag(MODEL_NAME);
    this.out.element(HAS_GLOBAL_ID, false);
    this.out.emptyTag(GLOBAL_ID_FIELD_NAME);
    this.out.emptyTag(RASTER_FIELD_NAME);
    this.out.startTag(EXTENSION_PROPERTIES);
    this.out.attribute(XsiConstants.TYPE, PROPERTY_SET_TYPE);
    this.out.startTag(PROPERTY_ARRAY);
    this.out.attribute(XsiConstants.TYPE, PROPERTY_ARRAY_TYPE);
    this.out.endTag(PROPERTY_ARRAY);
    this.out.endTag(EXTENSION_PROPERTIES);
    this.out.startTag(CONTROLLER_MEMBERSHIPS);
    this.out.attribute(XsiConstants.TYPE, CONTROLLER_MEMBERSHIPS_TYPE);
    this.out.endTag(CONTROLLER_MEMBERSHIPS);
    if (hasGeometry) {
        this.out.element(FEATURE_TYPE, FEATURE_TYPE_SIMPLE);
        this.out.element(SHAPE_TYPE, this.geometryType);
        this.out.element(SHAPE_FIELD_NAME, geometryField.getName());
        final GeometryFactory geometryFactory = geometryField.getProperty(FieldProperties.GEOMETRY_FACTORY);
        this.out.element(HAS_M, false);
        this.out.element(HAS_Z, geometryFactory.hasZ());
        this.out.element(HAS_SPATIAL_INDEX, false);
        this.out.emptyTag(AREA_FIELD_NAME);
        this.out.emptyTag(LENGTH_FIELD_NAME);
        writeExtent(geometryFactory);
        writeSpatialReference(geometryFactory);
    }
    this.out.endTag(DATA_ELEMENT);
}
Also used : Punctual(com.revolsys.geometry.model.Punctual) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Lineal(com.revolsys.geometry.model.Lineal) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) Timestamp(java.sql.Timestamp)

Aggregations

Polygon (com.revolsys.geometry.model.Polygon)147 Point (com.revolsys.geometry.model.Point)66 LinearRing (com.revolsys.geometry.model.LinearRing)54 LineString (com.revolsys.geometry.model.LineString)39 Geometry (com.revolsys.geometry.model.Geometry)34 ArrayList (java.util.ArrayList)30 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)22 Polygonal (com.revolsys.geometry.model.Polygonal)17 BoundingBox (com.revolsys.geometry.model.BoundingBox)14 Punctual (com.revolsys.geometry.model.Punctual)12 Test (org.junit.Test)12 Lineal (com.revolsys.geometry.model.Lineal)11 BaseCloseable (com.revolsys.io.BaseCloseable)7 List (java.util.List)7 PolygonEditor (com.revolsys.geometry.model.editor.PolygonEditor)6 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)6 Vertex (com.revolsys.geometry.model.vertex.Vertex)6 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)3 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)3 Graphics2D (java.awt.Graphics2D)3