![]() ![]() 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. There isn't nearly as much difference in geographic coordinate systems such as WGS84.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. The projected coordinate systems basically create a Cartesian plane on the surface of the globe, and the choice of origin, scale and other parameters are specific to each projection. Unfortunately, if you don't know what coordinate system your x and y points are in, it can become a frustrating game of trial and error. Names(box) <- NULL # removing non-complient labelsīox2 <- box + c(-buffer, -buffer, buffer, buffer) # bufferingīase_map <- get_map(location = box2, source = "osm") # getting base map Let's remove it so we can focus on the good points # let's exclude point 3 for nowīox <- st_bbox(my_latlon_df) # bounding box The no location information is going to cause problems, since it will plot at the origin of the state plane coordinate plane, which is down in Arkansas somewhere. We now have geographic coordinates with lat and long as columns of our data frame. # X1 CodedMonth Description geometry lat lon # proj4string: +proj=longlat +datum=WGS84 +no_defs # Simple feature collection with 6 features and 5 fields Mutate( lat= st_coordinates(my_latlon_df), Louis), My first guess was EPSG 26996 (NAD83 / Missouri East USFT), but that plotted in the middle of lake Huron, so I tried ESRI: 102696. In order to get this to work you need to know what coordinate system you are working with, and based on the description you provide (State Plane NAD83 and are near St. You can use the sf package to convert it to a simple features geography. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |