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;
}
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;
}
}
}
}
}
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;
}
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;
}
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();
}
}
Aggregations