I have been trying to use JTS within Apache Ignite in correlation with GPS coordinates.
So far I am not sure how or if those could interact. For example if I calculate a distance between two geometries, I will have a planar distance, but how would I convert it back to distance at the surface of the earth ?
For reference here is some code I used, I am not sure the transformations are correct though, but it's not the root of the problem:
Coordinate coord1 = convertToRect(resultCoord.y, resultCoord.x, 0.0);
Coordinate coord2 = convertToRect(latitude, longitude, 0.0);
double dist = new GeometryFactory().createPoint(coord1).distance(new GeometryFactory().createPoint(coord2));
...
private Coordinate convertToRect(Double lat, Double lon, Double alt) {
MathTransform ecefTransform = org.geotools.referencing.CRS.findMathTransform(DefaultGeographicCRS.WGS84_3D, DefaultGeocentricCRS.CARTESIAN);
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
Point p = geometryFactory.createPoint(new Coordinate(lat, lon, alt));
Geometry tp = JTS.transform(p, ecefTransform);
return tp.getCoordinate();
}
So maybe JTS is not meant to be used to perform geolocation on earth ? Otherwise would you know where I could find references of such usage ?
For reference the used libs:
compile 'org.opengis:geoapi:3.0.1'
compile 'org.geotools:gt-api:2.7.5'
compile 'org.geotools:gt-shapefile:2.7.5'
compile group: 'org.apache.ignite', name: 'ignite-geospatial', version: '2.5.2'
Thanks
If you are looking for distance in meters, you could use the GeoTools libraries GeodeticCalculator. As a shorthand, JTS handles geometry and GeoTools (and other libraries) are designed to help with geography.
http://docs.geotools.org/stable/userguide/library/referencing/calculator.html
http://docs.geotools.org/stable/javadocs/org/geotools/referencing/GeodeticCalculator.html
Related
I'm trying to associate a set of points (lat, long) to an edge using osmnx library in Python.
I would like to find the nearest points to an edge within a distance x.
I have an edge and I would like to draw a circle and count how many points are into the circle, with a given radius. I have tha lat and long coordinates of each point but I don't know how to calculate the lat, long coordinate of the edge. I also have the coordinates lat, long of the nodes connected by that edge.
Thank you for your help.
import pandas as pd
from shapely.ops import transform
from functools import partial
import pyproj
from shapely.geometry import Point
mid_point = Point(lon,lat) # UNPROJECTED CO-ORDINATES OF MID-POINT OF AN EDGE
node_point = Point(lon_node, lat_node)# UNPROJECTED CO-ORDINATES OF THE NODE
x = 500 #DISTANCE IN METERS
#TRANSFORM INTO PROJECTED CO-ORDINATES
project = partial(pyproj.transform,pyproj.Proj(init='epsg:4326'),pyproj.Proj(init='epsg:3112'))
mid_point_projected = transform(project, mid_point)
node_point_projected = transform(project, node_point)
#CREATE BUFFER CIRCLE WITH DISTANCE X METRES WITH CENTRE AT EDGE MID-POINT
buffer_circle = mid_point_projected.buffer(x)
#PERFORM POINT-IN-POLYGON ANALYSIS TO CHECK WHETHER THE NODE FALLS WITHIN THE BUFFER CIRCLE
print(buffer_circle.contains(node_point_projected))
POINTS TO BE NOTED:
EPSG Geodetic Parameter Dataset is a structured dataset of Coordinate Reference Systems and Coordinate Transformations, accessible through this online registry (www.epsg-registry.org)
EPSG 4326 represents World Geodetic System (WGS84) (https://epsg.io/4326)(points on the Earth's surface represented in terms of latitude and longitude)
I have transformed it into EPSG 3112 representing GDA94 / Geoscience Australia Lambert (https://epsg.io/3112). You should transform it into the corresponding EPSG code for your study area.
I have a constant acceleration and I need to calculate the instantaneous speed and the travelled distance.
So we know that the speed is the integral of acceleration and the travelled distance is the integral of the speed.
Using systemC AMS with the TDF modeling formalism, there isn't the integral operator, but there is the Laplace transform operator instead.
The schema for the speed and distance calculation that I would realize is the follow:
NB:
// Declaration of private variables of SCA_TDF_MODULE
sca_tdf::sca_ltf_nd lft;
sca_util::sca_vector<double> num, den;
// initialisation of variables
num(0) = 1.0;
den(0) = 1.0;
So I thought that I could calculate the speed using the sca_tdf::sca_ltf_nd in this way:
if (throttle_is_active) {
speed.write(lft(num, den, 2.78)); // speed is an output port
// distance ....
}
But I'm not sure that is right, and I don't know how to save this value to calculate the travelled distance using the ltf again.
The definition of tdf module can be found here.
Anyone can help me please?
see also SystemC AMS Users Guide provided with the proof-of-concept library
The coefficients in SystemC-AMS are defined as follows:
H(s) = (num(0) + num(1)*s + num(2)*s**2 ...) / (den(0) + den(1)*s + den(2)*s**2 ...)
-> the coefficients for an integrator are:
num(0)=1.0;
den(0)=0.0;
den(1)=1.0;
I try to convert WGS84 points data from googlemaps to local x,y referential in meters. I looked to many post on this site and others, but the way to define the local referential to get true distances and angles has not been depicted in these elements.
To do this conversion, I’m using the Proj4.js library, based on the following instruction:
var LocalProjection = "+proj=merc +lat_ts=43.6 +lon_0=3.9 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs" //to define the local referential
proj4('WGS84',LocalProjection,Point)
However, when doing this, I got distances between points which doesn’t match the ones I measure on google maps, so I believe there is an issue in the definition of the local referential I cannot figure out.
Would you have any clue on this, and especially on the parameters of the local referential ?
Example:
I consider the following points, representative of the outline from a typical building.
var PointTopLeft=[43.587778, 3.868792]
var PointTopRight=[43.587744, 3.868873]
var PointBottomRight=[43.587695, 3.868743]
var PointBottomLeft=[43.587666, 3.868822]
The distance between two points in the above order is calculated to respectively 7.0m, 9.3m, 7.5m and 11m, using pythagora formula on the difference between points.
Distance between points TopLeft - BottomLeft and between points TopRight – BottomRight should be 10m according to measure done on google earth. Similarly, distance between points TopLeft - BottomRight and between points TopRight – BottomLeft should be 7.5m according to measure done on google earth.
MapKit has function MKMapPointForCoordinate, It accept lat lng as argument and return point x,y.
https://developer.apple.com/library/prerelease/ios/documentation/MapKit/Reference/MapKitFunctionsReference/index.html
lat = 59.90738808515509
lng = 10.724523067474365
if we pass above lat, lng then function return
x = 142214284, y = 78089986
I check with lag lng wot UTM but it gives different result
http://www.latlong.net/lat-long-utm.html
MKMapPointForCoordinate doesn't return UTM Coordinates.
Coordinates refer to a position on the earth (a pseudo-sphere), but sometimes you need to do calculation refering to a 2D map (much simpler) and then convert again to coordinates. This is the goal of the conversion.
So, the MKMapPoint struct returned by MKMapPointForCoordinate is a 2D representation of the coordinates, but it doesn't match any standard known.
At this link: https://developer.apple.com/library/prerelease/ios/documentation/MapKit/Reference/MapKitDataTypesReference/index.html#//apple_ref/doc/c_ref/MKMapPoint
in the MKMapPoint documentation, you can read:
The actual units of a map point are tied to the underlying units used
to draw the contents of an MKMapView, but you should never need to
worry about these units directly. You use map points primarily to
simplify computations that would be complex to do using coordinate
values on a curved surface.
EDIT
for Coordinates-UTM Conversion in a previous project I used this Open Source Code
I wonder is there a way to convert actual street map coordinates to a set of GPS coordinates. I was thinking if I have a set of GPS coordinates on the corners of a rectangular street map, I could virtually put a GPS coordinate to any point in that area. It is logical but I am not sure how to do it.
The Geotools Java project has all the tools you need to transform from one coordinate system to another. I'm not aware of anything similar in C++ though I'm afraid.
There are an absolute wealth of coordinate systems out there (see: http://en.wikipedia.org/wiki/Geographic_coordinate_system), so you'd need to be more specific about the format in which you have your street map coordinates for me to give any more detail.
I think I get the concept. You need two ingredients for that:
1. Scale and..
2. Corner sample.
It's easy to make a program to offset your marked points on the map
but these requires the "Scale" (ex. 1-inch : 121001-meters) and the
sample of "coordinate" in at least one of any of the four corners
(top-left,top-right,bottom-left,bottom-right) for use to offset and
get.
Out of these variables needed, we could easily extract to get the
coords marked on your map.
MAJOR EDIT:
(Note: Disregard what I've written earlier above)
Variables:
mw = 2d mapwidth
mh = 2d mapheight
x = your 2d x coordinate
y = your 2d y coordinate
lat = latitude (our N or ?)
lon = longitude (our N or ?)
Formula:
lat = 180 + ( (x / mw) * 360) )
long = 90 + ( (y / mh) * 360) )
Explanation:
Following the formulas which are used:
x = (mw) * (180 + latitude) / 360
y = (mh) * (90 + longitude) / 180
I've personally transposed the formula above to find our latitude and longitude.
I hope this solves your problem and this is the appropriate answer for your question.
Don't forget to up my answer to save my honor from the humiliation earlier. jk. :)