Search in sources :

Example 1 with CoordinateArraySequence

use of com.vividsolutions.jts.geom.impl.CoordinateArraySequence in project activityinfo by bedatadriven.

the class MySqlUpdateTest method updateGeometry.

@Test
public void updateGeometry() throws SQLException {
    userId = 3;
    ResourceId formId = CuidAdapter.adminLevelFormClass(1);
    ResourceId recordId = entity(1);
    ResourceId fieldId = CuidAdapter.field(formId, CuidAdapter.GEOMETRY_FIELD);
    Optional<FormStorage> storage = catalog.getForm(formId);
    GeometryFactory factory = new GeometryFactory();
    Polygon polygon = new Polygon(new LinearRing(new CoordinateArraySequence(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 0), new Coordinate(101, 1), new Coordinate(100, 1), new Coordinate(100, 0) }), factory), new LinearRing[0], factory);
    storage.get().updateGeometry(recordId, fieldId, polygon);
    query(formId, "_id", "ST_XMIN(boundary)", "ST_XMAX(boundary)");
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) Coordinate(com.vividsolutions.jts.geom.Coordinate) Polygon(com.vividsolutions.jts.geom.Polygon) LinearRing(com.vividsolutions.jts.geom.LinearRing) CoordinateArraySequence(com.vividsolutions.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test)

Example 2 with CoordinateArraySequence

use of com.vividsolutions.jts.geom.impl.CoordinateArraySequence in project OpenTripPlanner by opentripplanner.

the class ConcaveHull method transformIntoPointGeometryCollection.

/**
 * Transform into GeometryCollection.
 *
 * @param geom
 * 		input geometry
 * @return
 * 		a geometry collection
 */
private static GeometryCollection transformIntoPointGeometryCollection(Geometry geom) {
    UniqueCoordinateArrayFilter filter = new UniqueCoordinateArrayFilter();
    geom.apply(filter);
    Coordinate[] coord = filter.getCoordinates();
    Geometry[] geometries = new Geometry[coord.length];
    for (int i = 0; i < coord.length; i++) {
        Coordinate[] c = new Coordinate[] { coord[i] };
        CoordinateArraySequence cs = new CoordinateArraySequence(c);
        geometries[i] = new Point(cs, geom.getFactory());
    }
    return new GeometryCollection(geometries, geom.getFactory());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) UniqueCoordinateArrayFilter(com.vividsolutions.jts.util.UniqueCoordinateArrayFilter) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Point(com.vividsolutions.jts.geom.Point) CoordinateArraySequence(com.vividsolutions.jts.geom.impl.CoordinateArraySequence)

Example 3 with CoordinateArraySequence

use of com.vividsolutions.jts.geom.impl.CoordinateArraySequence in project coastal-hazards by USGS-CIDA.

the class CRSUtils method buildLineString.

private static LineString buildLineString(List<Coordinate> coords) {
    LineString line;
    try {
        CoordinateSequence seq = new CoordinateArraySequence(coords.toArray(new Coordinate[coords.size()]));
        line = new LineString(seq, geometryFactory);
    } catch (Exception e) {
        LOGGER.error("Failed to build line string from list of coordinates", e);
        line = null;
    }
    return line;
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) FactoryException(org.opengis.referencing.FactoryException) UnsupportedFeatureTypeException(gov.usgs.cida.coastalhazards.exceptions.UnsupportedFeatureTypeException) TransformException(org.opengis.referencing.operation.TransformException) AttributeNotANumberException(gov.usgs.cida.coastalhazards.exceptions.AttributeNotANumberException) CoordinateArraySequence(com.vividsolutions.jts.geom.impl.CoordinateArraySequence)

Example 4 with CoordinateArraySequence

use of com.vividsolutions.jts.geom.impl.CoordinateArraySequence in project OpenTripPlanner by opentripplanner.

the class ConcaveHull method transformIntoPointGeometryCollection.

/**
 * Transform into GeometryCollection.
 *
 * @param geom
 * 		input geometry
 * @return
 * 		a geometry collection
 */
private static GeometryCollection transformIntoPointGeometryCollection(GeometryCollection gc) {
    UniqueCoordinateArrayFilter filter = new UniqueCoordinateArrayFilter();
    gc.apply(filter);
    Coordinate[] coord = filter.getCoordinates();
    Geometry[] geometries = new Geometry[coord.length];
    for (int i = 0; i < coord.length; i++) {
        Coordinate[] c = new Coordinate[] { coord[i] };
        CoordinateArraySequence cs = new CoordinateArraySequence(c);
        geometries[i] = new Point(cs, gc.getFactory());
    }
    return new GeometryCollection(geometries, gc.getFactory());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) UniqueCoordinateArrayFilter(com.vividsolutions.jts.util.UniqueCoordinateArrayFilter) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Point(com.vividsolutions.jts.geom.Point) CoordinateArraySequence(com.vividsolutions.jts.geom.impl.CoordinateArraySequence)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)4 CoordinateArraySequence (com.vividsolutions.jts.geom.impl.CoordinateArraySequence)4 Geometry (com.vividsolutions.jts.geom.Geometry)2 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)2 Point (com.vividsolutions.jts.geom.Point)2 UniqueCoordinateArrayFilter (com.vividsolutions.jts.util.UniqueCoordinateArrayFilter)2 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)1 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 LineString (com.vividsolutions.jts.geom.LineString)1 LinearRing (com.vividsolutions.jts.geom.LinearRing)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 AttributeNotANumberException (gov.usgs.cida.coastalhazards.exceptions.AttributeNotANumberException)1 UnsupportedFeatureTypeException (gov.usgs.cida.coastalhazards.exceptions.UnsupportedFeatureTypeException)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 FormStorage (org.activityinfo.store.spi.FormStorage)1 Test (org.junit.Test)1 FactoryException (org.opengis.referencing.FactoryException)1 TransformException (org.opengis.referencing.operation.TransformException)1