Search in sources :

Example 61 with Point

use of com.vividsolutions.jts.geom.Point in project Osmand by osmandapp.

the class MapillaryImageDialog method acquireSequenceImages.

private void acquireSequenceImages() {
    fetchTiles();
    List<MapillaryImage> sequenceImages = new ArrayList<>();
    if (!Algorithms.isEmpty(sequenceId)) {
        double px, py;
        for (Pair<QuadPointDouble, GeometryTile> pt : tiles) {
            QuadPointDouble point = pt.first;
            GeometryTile tile = pt.second;
            for (Geometry g : tile.getData()) {
                if (g instanceof Point && !g.isEmpty() && g.getUserData() != null && g.getUserData() instanceof HashMap) {
                    HashMap userData = (HashMap) g.getUserData();
                    String sequenceId = (String) userData.get(SEQUENCE_ID_KEY);
                    if (this.sequenceId.equals(sequenceId)) {
                        Point p = (Point) g;
                        px = p.getCoordinate().x / EXTENT;
                        py = p.getCoordinate().y / EXTENT;
                        double lat = MapUtils.getLatitudeFromTile(MIN_IMAGE_LAYER_ZOOM, point.y + py);
                        double lon = MapUtils.getLongitudeFromTile(MIN_IMAGE_LAYER_ZOOM, point.x + px);
                        MapillaryImage image = new MapillaryImage(lat, lon);
                        if (image.setData(userData)) {
                            sequenceImages.add(image);
                        }
                    }
                }
            }
        }
    }
    Collections.sort(sequenceImages, (img1, img2) -> Long.compare(img1.getCapturedAt(), img2.getCapturedAt()));
    this.sequenceImages = sequenceImages;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Point(com.vividsolutions.jts.geom.Point) GeometryTile(net.osmand.data.GeometryTile) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 62 with Point

use of com.vividsolutions.jts.geom.Point in project Osmand by osmandapp.

the class MapillaryImageDialog method acquireSequenceKey.

private void acquireSequenceKey() {
    fetchTiles();
    for (Pair<QuadPointDouble, GeometryTile> pt : tiles) {
        GeometryTile tile = pt.second;
        for (Geometry g : tile.getData()) {
            if (g instanceof Point && !g.isEmpty() && g.getUserData() != null && g.getUserData() instanceof HashMap) {
                HashMap userData = (HashMap) g.getUserData();
                String imageId = (String) userData.get(IMAGE_ID_KEY);
                if (this.imageId.equals(imageId)) {
                    sequenceId = (String) userData.get(SEQUENCE_ID_KEY);
                    return;
                }
            }
        }
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) HashMap(java.util.HashMap) Point(com.vividsolutions.jts.geom.Point) GeometryTile(net.osmand.data.GeometryTile) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 63 with Point

use of com.vividsolutions.jts.geom.Point in project eol-globi-data by jhpoelen.

the class DatasetImporterForRaymond method calculateCentroidOfBBox.

protected static LatLng calculateCentroidOfBBox(double left, double top, double right, double bottom) {
    LatLng latLng;
    if (left == right && top == bottom) {
        latLng = new LatLng(top, left);
    } else {
        Coordinate[] points = { GeoUtil.getCoordinate(top, left), GeoUtil.getCoordinate(top, right), GeoUtil.getCoordinate(bottom, right), GeoUtil.getCoordinate(bottom, left), GeoUtil.getCoordinate(top, left) };
        GeometryFactory geometryFactory = new GeometryFactory();
        Polygon polygon = geometryFactory.createPolygon(points);
        Point centroid = polygon.getCentroid();
        latLng = new LatLng(centroid.getCoordinate().y, centroid.getCoordinate().x);
    }
    return latLng;
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) LatLng(org.eol.globi.geo.LatLng) Point(com.vividsolutions.jts.geom.Point) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 64 with Point

use of com.vividsolutions.jts.geom.Point in project structr by structr.

the class GeoFunction method getCoordinate.

protected Coordinate getCoordinate(final Object source) {
    if (source instanceof Point) {
        return ((Point) source).getCoordinate();
    } else if (source instanceof Geometry) {
        return ((Geometry) source).getCoordinate();
    } else if (source instanceof Coordinate) {
        return (Coordinate) source;
    } else if (source instanceof List) {
        final List point = (List) source;
        final Object x = point.get(0);
        final Object y = point.get(1);
        final Double px = this.getDoubleOrNull(x);
        final Double py = this.getDoubleOrNull(y);
        if (px != null && py != null) {
            return new Coordinate(px, py);
        }
    } else if (source instanceof Map) {
        final Map point = (Map) source;
        if (point.containsKey("x") && point.containsKey("y")) {
            final Double px = this.getDoubleOrNull(point.get("x"));
            final Double py = this.getDoubleOrNull(point.get("y"));
            if (px != null && py != null) {
                return new Coordinate(px, py);
            }
        } else if (point.containsKey("latitude") && point.containsKey("longitude")) {
            final Double plat = this.getDoubleOrNull(point.get("latitude"));
            final Double plon = this.getDoubleOrNull(point.get("longitude"));
            if (plat != null && plon != null) {
                return new Coordinate(plat, plon);
            }
        } else if (point.containsKey("lat") && point.containsKey("lon")) {
            final Double plat = this.getDoubleOrNull(point.get("lat"));
            final Double plon = this.getDoubleOrNull(point.get("lon"));
            if (plat != null && plon != null) {
                return new Coordinate(plat, plon);
            }
        } else {
            logger.warn("Unknown coordinate object, don't know how to handle {}, ignoring", source);
        }
    } else {
        logger.warn("Unknown coordinate object, don't know how to handle {}, ignoring", source);
    }
    return null;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) List(java.util.List) Point(com.vividsolutions.jts.geom.Point) Map(java.util.Map)

Example 65 with Point

use of com.vividsolutions.jts.geom.Point in project tests by datanucleus.

the class JtsGeometryMappingTest method testUserDataMappingWithString.

public void testUserDataMappingWithString() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    Point point = (Point) wktReader.read("POINT(10 10)");
    point.setSRID(-1);
    Object userData = "UserDataString";
    point.setUserData(userData);
    SamplePoint samplePoint;
    SamplePoint samplePoint_read;
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        samplePoint = new SamplePoint(12001, "UserDataWithString", point);
        em.persist(samplePoint);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
    em = emf.createEntityManager();
    tx = em.getTransaction();
    try {
        tx.begin();
        samplePoint_read = (SamplePoint) em.find(SamplePoint.class, new Long(12001));
        assertEquals(samplePoint, samplePoint_read);
        assertNotNull(samplePoint_read.getGeom().getUserData());
        assertEquals(String.class, samplePoint_read.getGeom().getUserData().getClass());
        assertEquals(userData, samplePoint_read.getGeom().getUserData());
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}
Also used : SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) Point(com.vividsolutions.jts.geom.Point)

Aggregations

Point (com.vividsolutions.jts.geom.Point)157 Geometry (com.vividsolutions.jts.geom.Geometry)53 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)49 Coordinate (com.vividsolutions.jts.geom.Coordinate)46 ArrayList (java.util.ArrayList)27 Polygon (com.vividsolutions.jts.geom.Polygon)26 LineString (com.vividsolutions.jts.geom.LineString)25 SamplePoint (org.datanucleus.samples.jtsgeometry.SamplePoint)22 List (java.util.List)20 PersistenceManager (javax.jdo.PersistenceManager)19 Transaction (javax.jdo.Transaction)19 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)18 Query (javax.jdo.Query)17 Test (org.junit.Test)17 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)15 HashMap (java.util.HashMap)15 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)12 QuadPointDouble (net.osmand.data.QuadPointDouble)12 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)10 LinearRing (com.vividsolutions.jts.geom.LinearRing)10