Search in sources :

Example 46 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project UVMS-ActivityModule-APP by UnionVMS.

the class FluxMessageServiceBean method getGeometryFromSpatial.

/**
 * Get Geometry information from spatial for FLUXLocation code
 * @param fluxLocationIdentifier
 * @return
 */
private Geometry getGeometryFromSpatial(String fluxLocationIdentifier) {
    log.info("Get Geometry from Spatial for:" + fluxLocationIdentifier);
    if (fluxLocationIdentifier == null) {
        return null;
    }
    Geometry geometry = null;
    try {
        String geometryWkt = spatialModuleService.getGeometryForPortCode(fluxLocationIdentifier);
        if (geometryWkt != null) {
            Geometry value = GeometryMapper.INSTANCE.wktToGeometry(geometryWkt).getValue();
            Coordinate[] coordinates = value.getCoordinates();
            if (coordinates.length > 0) {
                Coordinate coordinate = coordinates[0];
                double x = coordinate.x;
                double y = coordinate.y;
                geometry = GeometryUtils.createPoint(x, y);
            }
        }
        log.debug(" Geometry received from Spatial for:" + fluxLocationIdentifier + "  :" + geometryWkt);
    } catch (ServiceException | ParseException e) {
        log.error("Exception while trying to get geometry from spatial", e);
    }
    return geometry;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) Coordinate(com.vividsolutions.jts.geom.Coordinate) ParseException(com.vividsolutions.jts.io.ParseException)

Example 47 with Coordinate

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

the class BatchGeocoder method addPoint.

public void addPoint(double x, double y) {
    int pointIndex = points.size();
    // add the point to the list
    points.add(gf.createPoint(new Coordinate(x, y)));
    // index the point
    index.add(new SweepLineInterval(x, x, pointIndex));
    // add an empty result
    results.add(new ArrayList<AdminEntity>());
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) Coordinate(com.vividsolutions.jts.geom.Coordinate) SweepLineInterval(com.vividsolutions.jts.index.sweepline.SweepLineInterval) Point(com.vividsolutions.jts.geom.Point)

Example 48 with Coordinate

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

the class Geocoder method geocode.

/**
 * Geocode a single point to a list of admin entities
 *
 * @param latitude
 * @param longitude
 * @return
 */
public List<AdminEntity> geocode(double latitude, double longitude) {
    Point point = gf.createPoint(new Coordinate(longitude, latitude));
    Session session = sessionProvider.get();
    Criteria criteria = session.createCriteria(AdminEntity.class);
    criteria.add(SpatialRestrictions.contains("geometry", point));
    // mysql seems to check only the MBRs. We need to verify
    // that the point is actually contained by the geometry
    List<AdminEntity> containedByMbr = criteria.list();
    List<AdminEntity> contains = Lists.newArrayList();
    for (AdminEntity entity : containedByMbr) {
        if (JtsUtil.contains(entity.getGeometry(), point)) {
            contains.add(entity);
        }
    }
    return contains;
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 49 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate 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 50 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project sldeditor by robward-scisys.

the class ExampleLineImpl method getLine.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.datasource.impl.ExampleLineInterface#getLine()
     */
@Override
public LineString getLine() {
    if (line == null) {
        // CHECKSTYLE:OFF
        double[][] rawLocations = new double[][] { { -123.167725, 48.502048 }, { -123.464355, 48.297812 }, { -124.738770, 48.603858 }, { -125.189209, 48.828566 }, { -125.112305, 48.951366 }, { -125.507812, 48.929718 }, { -125.870361, 49.145784 }, { -126.035156, 49.167339 }, { -126.112061, 49.253465 }, { -126.243896, 49.282140 }, { -126.287842, 49.360912 }, { -126.397705, 49.410973 }, { -126.573486, 49.375220 }, { -126.584473, 49.560852 }, { -126.815186, 49.610710 }, { -127.012939, 49.745781 }, { -126.947021, 49.788357 }, { -127.166748, 49.852152 }, { -127.518311, 50.113533 }, { -127.814941, 50.078295 }, { -127.957764, 50.120578 }, { -127.825928, 50.254230 }, { -128.012695, 50.331436 }, { -127.946777, 50.450509 }, { -128.122559, 50.457504 }, { -128.364258, 50.652943 }, { -128.342285, 50.792047 }, { -128.100586, 50.882243 }, { -127.858887, 50.944584 }, { -127.518311, 50.798991 }, { -127.221680, 50.639010 } };
        // CHECKSTYLE:ON
        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
        Coordinate[] coords = new Coordinate[rawLocations.length];
        int index = 0;
        for (double[] point : rawLocations) {
            Coordinate c = new Coordinate(point[0], point[1]);
            coords[index] = c;
            index++;
        }
        line = geometryFactory.createLineString(coords);
    }
    return line;
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)336 LineString (com.vividsolutions.jts.geom.LineString)70 Geometry (com.vividsolutions.jts.geom.Geometry)67 ArrayList (java.util.ArrayList)65 Test (org.junit.Test)60 Point (com.vividsolutions.jts.geom.Point)52 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)48 Polygon (com.vividsolutions.jts.geom.Polygon)30 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)27 SimpleFeature (org.opengis.feature.simple.SimpleFeature)23 LinearRing (com.vividsolutions.jts.geom.LinearRing)22 Vertex (org.opentripplanner.routing.graph.Vertex)22 Envelope (com.vividsolutions.jts.geom.Envelope)21 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)20 Edge (org.opentripplanner.routing.graph.Edge)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 File (java.io.File)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)11