Converting from UTM to Lat/Long coordinates given a Proj4 String - gis

I would like to convert an Easting/Northing coordinate to Latitude/Longitude given the following information.
Datum: QND95 / Qatar National Grid
Proj4 String: +proj=longlat +ellps=intl +towgs84=-119.425,-303.659,-11.0006,1.1643,0.174458,1.09626,3.65706 +no_defs
Ellipsoid: Hayford Intl 1924 (a=6378388, b=6356911.94612795)
Any pointers on how to use a Proj4 library to figure this out is greatly appreciated.
Edit: The EPSG website does this transformation correctly. I would like to know how to reproduce this programmatically:
https://epsg.io/transform#s_srs=2932&t_srs=4326&x=363377.0000000&y=169393.0000000

Related

Distance between POINT and GEOMETRYCOLLECTION objects in MYSQL

MYSQL ver 5.7
Requirement:
I have a bunch of POINT geometries in MYSQL table and I have to find all the POINT geometries that are within 5km distance/radius of a GEOMETRYCOLLECTION object.
GEOMETRYCOLLECTION may contain more than one type of geometries like POINT, POLYGON etc.
Sample GEOMETRYCOLLECTION data:
SET #g1 = ST_GeomFromText('GEOMETRYCOLLECTION(POINT (-156.366489591715 66.913750389327),POLYGON ((-156.357608905242 66.906958164897, -156.360302383363 66.9066027336476, -156.361997104194 66.9067073607308, -156.363616093774 66.9066368440642, -156.365477697938 66.9065867326059, -156.368127298976 66.9065970034393, -156.370061891681 66.9066888794808, -156.37182258022 66.9068547305222, -156.373286981259 66.9070724523969, -156.374390675008 66.9072952721882, -156.376359777088 66.9077681138541, -156.377706173961 66.9080113180204, -156.379222192708 66.9081328753119, -156.380729601039 66.9081591586452, -156.382562289578 66.9081211961453, -156.387571662487 66.9099676951007, -156.389320598943 66.9125180930134, -156.389291120818 66.9145787836353, -156.384722634367 66.9167899596735, -156.37955035 66.9195246586276, -156.372520662511 66.9209119638337, -156.360432280238 66.9215118034161, -156.355776993787 66.9203754471679, -156.34906598338 66.9180659711298, -156.347941981299 66.9174007836309, -156.346853913592 66.9167568252985, -156.34605399901 66.9158971169665, -156.346982815675 66.9151925950926, -156.346794497967 66.9144321773854, -156.345642955261 66.9140107294695, -156.343831364638 66.9136152003034, -156.342996512556 66.9130307378043, -156.343113243806 66.9123137492637, -156.343498096931 66.9119029992644, -156.344661664637 66.9111819440571, -156.345080786511 66.9105884961414, -156.345524286511 66.9099605023924, -156.347168040675 66.9098486503092, -156.348952756297 66.9096090419763, -156.348689200048 66.9089614565606, -156.349495732338 66.908706844061, -156.350786711503 66.9082992794783, -156.352211271917 66.9083472388533, -156.353952768789 66.90829894302, -156.355389368787 66.9082072242701, -156.356512531285 66.9079768284371, -156.356677961493 66.9078075857291, -156.356422527119 66.907644261771, -156.355901372953 66.9072802273965, -156.357608905242 66.906958164897)))');
Sample POINT data:
SET #p1 = ST_GeomFromText('GEOMETRYCOLLECTION(POINT (-156.342840017 66.9320439348))');
I have tried ST_DISTANCE_SPHERE(#g1,#p1) spatial function (which returns the value in meters) but it seems it doesn't support geometry types other than POINT and MULTIPOINT.
Then I have used:
ST_DISTANCE(#g1,#p1)
'0.015301834064271899'
I am unable to understand the what is the UNIT of this returned value in MYSQL 5.7?
I have searched a lot on the internet and there is no proper documentation available regarding the same. In POSTGIS, this can be done but I am struggling to do this in MYSQL ver 5.7.
Any help is appreciated.
Thanks in advance!
ST_Distance returns "distance" in degrees here - i.e. the flat map view of the shortest distance between shapes. This value cannot be mapped to real distance, as real world distance of 1 degree along parallel is different from distance of 1 degree along meridian except near the equator.
Looks like MySQL cannot correctly compute distance here. You would be better served by systems with more geospatial support, like PostgreSQL + PostGIS, or Google BigQuery, etc. They give you correct answer, you just need to replace ST_GeomFromText with ST_GeogFromText to work with spherical geographies.

Error when using spatial reference EPSG:3440 in gdal2tiles.py

I was using gdal2tiles.py with spatial reference WSG84 and it was working fine. However, when I changed to spatial reference EPSG:3440. I got the the following error:
First, I run the command:
gdal_translate -of VRT -a_srs EPSG:3440 -gcp 0 0 58.068451479718924 23.65512391903488 -gcp 21816 0 58.126966134442846 23.65512391903488 -gcp 21816 14871 58.126966134442846 23.6185834507829 myinputimage.png myoutput.vrt
Than, I run the command:
python gdal2tiles.py myoutput.vrt
I got the following error:
Is there is way to fix this error or use similar spatial reference which doesn't have this error. Notice, this error happen only when using spatial reference other than WSG84.
EDIT: I guess the issue could be that spatial reference EPSG:3440 is not inculded, but the question remain, is there away to add it to gdal reference database.
The EPSG:3440 is a projected system. The correct definition for accuracy 0.5 meter would be probably:
+proj=utm +zone=40 +ellps=clrk80 +towgs84=-180.624,-225.516,173.919,-0.81,-1.898,8.336,16.71006 +units=m +no_defs
If I have a look at http://epsg.io/3440-1439 it tells:
Projected bounds:
-35283.71 1840661.51
789562.66 2942956.58
In your command above you assign ground control points which looks like geodetic (latitude longitude numbers) such as 58.068451479718924. This is very probably wrong - as the numbers you assign are not in the projected bounds range.
You must very use in the -gcp parameter of the gdal_translate numbers which are bigger - already projected and in the above range.
It is possible to transform your lat/lon from WGS84 via the online interface at:
http://epsg.io/3440-1439/map and assign in the -gcp argument the transformed numbers.
You have marked your query with tag maptiler which refers to http://www.maptiler.com/. This tool would be able to assign the coordinates visually as well without a need to create VRTs - so you can click on your image and copy&paste the above coordinates in a projected system.
MapTiler generates a viewer which display the EPSG:3440 tiles in OpenLayers or transform these to a spherical mercator tiles for overlays with Google or OSM or use in mobile apps.
BTW glad to hear you use the systems gdal2tiles, maptiler and http://epsg.io/ which we have developed...

How can I calculate distance (in meters) between two points on Google map

I'm using an L80 GPS module together with my 8-bit processor. GPS module responds with a massage in NMEA format, giving me information about the date, time, latitude, longitude, altitude (if possible), number of satellites etc.
Latitude and longitude information of NMEA are in the form of degrees and minutes (DD°MM.mmm').
I'm able to convert them into only degrees notation (DD.dddddd°).
I have the following problem: Given a particular location (e.g. 48.858125, 2.294398) and a safety radius of, let's say, 50 meters (no more than 300 meters), how to determine weather (a, b) point is within a safety circle or not?
Can you help me figuring out the math hiding behind?
In short, I would like you to help me determine distance in meters between two points on Earth represented in angular coordinate system. Are there any math guru willing to help me?
Note that my point of calculations is my processor.
I know that, having latitudes and longitudes in degrees, my points are represented in an angular coordinate system, not Cartesian (linear) one.I also know that Universal Transferse Mercator (UTM) representation of points on Earth is in Cartesian coordinate system. Is it, maybe, easier to transform degree notation (DD.dddddd°) into UTM notation? I know there are on-line tools that are able to do a conversion. However, I don't know the math.
Thank you very much for your time and effort to help me.
Sincerely,
Bojan
You can simply find distance b/w two points by longitude and latitude.
you can find reference code on this link.
Hope this helps.
Just use the haversine formula to calcualte the distance between two points on earth.
Search for term "haversine" and the name of your programming language.
Is it, maybe, easier to transform to UTM
No for sure not. It is very complex, and it gets extremly complex when the two points are located in different UTM zones.

Please explain ST_GeomFromText parameters

I am having trouble understanding ST_GeomFromText. It looks like there are 3 sets of 2 numbers. Why is that? Wouldn't coordinates just consist of a latitude and longitude?
Here is an example from http://postgis.net/docs/ST_GeomFromText.html:
SELECT ST_GeomFromText('LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)');
ST_GeomFromText() takes a WKT expression of a geometry object and
Constructs a PostGIS ST_Geometry object from the OGC Well-Known text representation.
The WKT expression in the example is a LINESTRING which is
a one-dimensional object representing a sequence of points and the line segments connecting them.
You might think a linestring would be two-dimensional, but it's not, because a line has no width or height. (Points are 0-dimensional, polygons are 2-dimensional).
So, by definition, that would have more than one set of coordinates. A pair of coordinates would be a POINT, not a linestring, and would look something like this, in conjunction with the function in question:
ST_GeomFromText('POINT (30 10)');
You may want to read up on some GIS fundamentals:
http://www.cise.ufl.edu/~mschneid/Service/Tutorials/TutorialSDT.pdf - excellent tutorial
http://www.opengeospatial.org/standards/orm - OGC Reference Model

How can I convert OSGB36 to latitude / longitude co-ordinates using VBA?

I have to calculate distances between map points as part of a project I am doing. The map points are provided in OSGB36 co-ordinates, e.g. 508800 / 181100 (being easting and northing). I have come across many functions to calculate the distance between 2 lat / longs and so would like to convert to these using VBA within an MS Access database.
Does anyone know how I can do this?
Thanks,
Steve
Rectilinear coordinates like this actually need nothing more than
http://en.wikipedia.org/wiki/Pythagorean_theorem
to calculate distances.
$d = sqrt(pow($e1-$e2,2)+pow($n1-$n2,2));
Where $d is the answer in meters. $e1,$n1 and $e2,$n2 are your easting/northings of the two points.