Search in sources :

Example 1 with GeometryCollection

use of com.vividsolutions.jts.geom.GeometryCollection in project hibernate-orm by hibernate.

the class GeometryEquality method test.

private boolean test(Geometry geom1, Geometry geom2, boolean ignoreSRID) {
    if (geom1 == null) {
        return geom2 == null;
    }
    if (geom1.isEmpty()) {
        return geom2.isEmpty();
    }
    if (!ignoreSRID && !equalSRID(geom1, geom2)) {
        return false;
    }
    if (geom1 instanceof GeometryCollection) {
        if (!(geom2 instanceof GeometryCollection)) {
            return false;
        }
        GeometryCollection expectedCollection = (GeometryCollection) geom1;
        GeometryCollection receivedCollection = (GeometryCollection) geom2;
        for (int partIndex = 0; partIndex < expectedCollection.getNumGeometries(); partIndex++) {
            Geometry partExpected = expectedCollection.getGeometryN(partIndex);
            Geometry partReceived = receivedCollection.getGeometryN(partIndex);
            if (!test(partExpected, partReceived, true)) {
                return false;
            }
        }
        return true;
    } else {
        return testSimpleGeometryEquality(geom1, geom2);
    }
}
Also used : GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Geometry(com.vividsolutions.jts.geom.Geometry)

Example 2 with GeometryCollection

use of com.vividsolutions.jts.geom.GeometryCollection in project series-rest-api by 52North.

the class GeoJSONTest method testGeometryCollectionWithZCoordinate.

@Test
public void testGeometryCollectionWithZCoordinate() throws GeoJSONException, IOException {
    GeometryCollection geometry = geometryFactory.createGeometryCollection(new Geometry[] { randomGeometryCollection(CRSUtils.EPSG_WGS84), randomGeometryCollection(2000) });
    geometry.apply(new RandomZCoordinateFilter());
    geometry.geometryChanged();
    readWriteTest(geometry);
}
Also used : GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Test(org.junit.Test)

Example 3 with GeometryCollection

use of com.vividsolutions.jts.geom.GeometryCollection in project series-rest-api by 52North.

the class GeoJSONTest method randomGeometryCollection.

private GeometryCollection randomGeometryCollection(int srid) {
    GeometryCollection geometry = geometryFactory.createGeometryCollection(new Geometry[] { randomPoint(srid), randomMultiPoint(srid), randomLineString(srid), randomMultiLineString(srid), randomPolygon(srid), randomMultiPolygon(srid) });
    geometry.setSRID(srid);
    return geometry;
}
Also used : GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection)

Example 4 with GeometryCollection

use of com.vividsolutions.jts.geom.GeometryCollection in project spatial-portal by AtlasOfLivingAustralia.

the class ShapefileUtils method saveShapefile.

public static void saveShapefile(File shpfile, String wktString, String name) {
    try {
        final SimpleFeatureType type = createFeatureType();
        List<SimpleFeature> features = new ArrayList<SimpleFeature>();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type);
        WKTReader wkt = new WKTReader();
        Geometry geom = wkt.read(wktString);
        if (geom instanceof GeometryCollection) {
            GeometryCollection gc = (GeometryCollection) geom;
            for (int i = 0; i < gc.getNumGeometries(); i++) {
                Geometry g = gc.getGeometryN(i);
                if (g instanceof Polygon) {
                    g = new GeometryBuilder().multiPolygon((Polygon) g);
                }
                featureBuilder.add(g);
                SimpleFeature feature = featureBuilder.buildFeature(null);
                feature.setAttribute("name", name);
                features.add(feature);
            }
        } else {
            Geometry g = geom;
            if (g instanceof Polygon) {
                g = new GeometryBuilder().multiPolygon((Polygon) g);
            }
            featureBuilder.add(g);
            SimpleFeature feature = featureBuilder.buildFeature(null);
            features.add(feature);
        }
        ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
        Map<String, Serializable> params = new HashMap<String, Serializable>();
        params.put("url", shpfile.toURI().toURL());
        params.put("create spatial index", Boolean.TRUE);
        ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
        newDataStore.createSchema(type);
        newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
        Transaction transaction = new DefaultTransaction("create");
        String typeName = newDataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = newDataStore.getFeatureSource(typeName);
        if (featureSource instanceof SimpleFeatureStore) {
            SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
            DefaultFeatureCollection collection = new DefaultFeatureCollection();
            collection.addAll(features);
            featureStore.setTransaction(transaction);
            try {
                featureStore.addFeatures(collection);
                transaction.commit();
            } catch (Exception problem) {
                LOGGER.error("error pricessing shape file: " + shpfile.getAbsolutePath(), problem);
                transaction.rollback();
            } finally {
                transaction.close();
            }
        }
        LOGGER.debug("Active Area shapefile written to: " + shpfile.getAbsolutePath());
    } catch (Exception e) {
        LOGGER.error("Unable to save shapefile: " + shpfile.getAbsolutePath(), e);
    }
}
Also used : Serializable(java.io.Serializable) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) ArrayList(java.util.ArrayList) WKTReader(com.vividsolutions.jts.io.WKTReader) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Geometry(com.vividsolutions.jts.geom.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) ShapefileDataStoreFactory(org.geotools.data.shapefile.ShapefileDataStoreFactory) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) GeometryBuilder(org.geotools.geometry.jts.GeometryBuilder) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 5 with GeometryCollection

use of com.vividsolutions.jts.geom.GeometryCollection in project ddf by codice.

the class Wfs20JTStoGML321Converter method createGeometryPropertyType.

private static GeometryPropertyType createGeometryPropertyType(Geometry geometry, String srsName) {
    final GeometryPropertyType geometryPropertyType = GML320_OBJECT_FACTORY.createGeometryPropertyType();
    if (geometry instanceof Point) {
        PointType pointType = convertToPointType((Point) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertPointTypeToJAXB(pointType));
    } else if (geometry instanceof LineString) {
        LineStringType lineStringType = convertToLineStringType((LineString) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertLineStringTypeToJAXB(lineStringType));
    } else if (geometry instanceof Polygon) {
        PolygonType polygonType = convertToPolygonType((Polygon) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertPolygonTypeToJAXB(polygonType));
    } else if (geometry instanceof MultiPoint) {
        MultiPointType multiPointType = convertToMultiPointType((MultiPoint) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiPointTypeToJAXB(multiPointType));
    } else if (geometry instanceof MultiLineString) {
        MultiCurveType multiCurveType = convertToMultiLineStringType((MultiLineString) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiCurveTypeToJAXB(multiCurveType));
    } else if (geometry instanceof MultiPolygon) {
        MultiSurfaceType multiSurfaceType = convertToMultiSurfaceType((MultiPolygon) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiSurfaceTypeToJAXB(multiSurfaceType));
    } else if (geometry instanceof GeometryCollection) {
        MultiGeometryType multiGeometryType = convertToMultiGeometryType((GeometryCollection) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiGeometryTypeToJAXB(multiGeometryType));
    } else {
        throw new IllegalArgumentException();
    }
    return geometryPropertyType;
}
Also used : MultiPoint(com.vividsolutions.jts.geom.MultiPoint) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiCurveType(net.opengis.gml.v_3_2_1.MultiCurveType) MultiGeometryType(net.opengis.gml.v_3_2_1.MultiGeometryType) PolygonType(net.opengis.gml.v_3_2_1.PolygonType) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) LineStringType(net.opengis.gml.v_3_2_1.LineStringType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) MultiSurfaceType(net.opengis.gml.v_3_2_1.MultiSurfaceType) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) PointType(net.opengis.gml.v_3_2_1.PointType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) GeometryPropertyType(net.opengis.gml.v_3_2_1.GeometryPropertyType)

Aggregations

GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)12 Geometry (com.vividsolutions.jts.geom.Geometry)6 LineString (com.vividsolutions.jts.geom.LineString)4 Point (com.vividsolutions.jts.geom.Point)4 Polygon (com.vividsolutions.jts.geom.Polygon)4 ArrayList (java.util.ArrayList)4 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)3 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 Serializable (java.io.Serializable)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)2 ParseException (com.vividsolutions.jts.io.ParseException)2 WKTReader (com.vividsolutions.jts.io.WKTReader)2 Test (org.junit.Test)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 Attribute (ddf.catalog.data.Attribute)1 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 Metacard (ddf.catalog.data.Metacard)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 Coordinate (de.micromata.opengis.kml.v_2_2_0.Coordinate)1