(For advice on precision in these coordinates please see Measuring accuracy of latitude and longitude?. To create subsets while keeping coordinates, rioxarray is my favorite way of doing it. Only when you project your data to X-Y, earth's curvature is taken into account. That's why there's no need to be finicky about accuracy in the conversion from meters to degrees: one part in a thousand would be more than good enough for any building. 2 Answers Sorted by: 0 You can interpolate, the coordinates. This would locate it at (lat, lon) = (45.000100, 6.500000) + (0.000180, -0.000127) = (45.000280, 6.499873).Īssuming the sensor locations are perfectly accurate, note that even a 5% error in these particular calculations would still place the final coordinates within 5%*20 = 1 meter of their correct locations. Therefore the object is displaced 10/78701 = 0.0001271 degrees west (which is the negative direction) and 20/111300 = 0.0001797 degrees north. ![]() The errors will be much smaller than one meter.įor example, suppose you locate an object 10 meters west and 20 meters north of a sensor at (lat, lon) = (45.000100, 6.500000) and the building's center is at latitude 45 degrees. ![]() For the latitude in the equation use the latitude of the middle of the building. Converting XY to lat and lng Ask Question Asked 6 years, 2 months ago Modified 3 years, 2 months ago Viewed 24k times 0 I'm new to GIS, and I have some tasks that have to work with lat and lng values. Each degree of longitude will be approximately 111300 * cos(latitude) meters (with the same possibility of making it a little more accurate with a little more preliminary work). To a high relative accuracy, in this application-where the region to be mapped will not extend more than a few hundred meters and it is not near either pole- you can treat lat-lon as a Cartesian coordinate system that uses two different linear units of measure.Įach degree of latitude will be approximately 111300 meters (and a more accurate value, which may differ from this by up to a few hundred meters, can be found once and for all by consulting tables or through a preliminary calculation). Again, you can rescale so that coordinates are rather than. In this case however, z=-1 is the south pole, z=1 is the north pole, x=1 and x=-1 are the prime meridian, and the dateline, and y=1 and y=-1 are 90 degrees East and 90 degrees West. If you approximate the earth's surface as a sphere, then the formulae should be x = sin(pi/2-lat) * cos(lon) ![]() If your positions only cover a small patch of the Earth, the errors may be acceptable to you.Ī second approach is to convert the longitude and latitude to (x, y, z) coordinates in 3d space. A good reference is Map Projections: A Working Manual. You should read about different map projections to see what you may be losing. However, this doesn't perfectly preserve spatial relationships because longitude and latitude are on a sphere (or an ellipsoid or geoid), and x,y coordinates are on a flat surface. Then, simply rescale your coordinates to be in the range. To do this, you can use the pyproj library. One obvious approach is to project it to some appropriate flat coordinate system. It depends on what metric you need to preserve. However, if you are using sklearn already, then you may as well use. You can then use numpy's built-in array methods to normalise your values. Note that ansform() also works on numpy arrays, so you can therefore transform your lon, lat arrays to x, y arrays. X, y = ansform(crs_wgs, crs_bng, input_lon, input_lat) # then cast your geographic coordinate pair to the projected system import pyproj as projĬrs_wgs = proj.Proj(init='epsg:4326') # assuming you're using WGS84 geographicĬrs_bng = proj.Proj(init='epsg:27700') # use a locally appropriate projected CRS a local UTM zone or regional system such as the British National Grid (EPSG code 27700). In other words you need to convert from your geographic coordinate system (most likely EPSG code 4326) to a local projected coordinate system, e.g. ![]() Use pyproj for converting your lng, lat pairs to a projected coordinate system. X, y = utm.from_latlon(input_lat, input_lon) The below conversion example would become: import utm easting, northing ordering for the respective from_latlon and to_latlon functions, per the docs. If utm coordinates are suitable for your purposes, then note that in lieu of pyproj, the utm package is now available and is simpler to use.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |