How can I edit the values of coordinates within a geojson file? - dictionary

I am trying to map a geojson file (A map of Alaska precincts, downloaded from the division of elections and then converted online to geojson) onto a choropleth map using folium, the problem is the coordinates are in 7-digit numbers like this:
[ -16624764.227, 8465801.1497 ]
I read on a similar post that this was most likely a US coordinate system like UTM or State Plane, and recommended using an API to reproject it. Is it also possible to access the coordinates directly such as with geopandas and divide them by 100000?

The data is most likely in a specific cartographic projection. You don't just want to divide by 100k - the data will likely have nonlinear transformations which have a different effect on the position depending on the location. See the GeoPandas docs on working with projections.
If the CRS of the data is correctly encoded, you can re-project the dataframe into lat/lons (e.g. WGS84, which has the EPSG Code 4326) using geopandas.GeoDataFrame.to_crs, e.g.:
df_latlon = df.to_crs("epsg:4326")

Related

how to convert world lat and long coordinates to something ONE simulator understands?

I have the coordinates of Manhattan in a .wkt file and an example of that file content is: LINESTRING (40.619605 -73.9584046, 40.6205286 -73.9585793, 40.6206127 -73.9585952)
ONE simulator does not recognize such coordinates to display the map of Manhattan and instead needs something that looks like this: LINESTRING (4883.179 10736.259, 4924.922 10811.716)
I'm not sure what format that is nor not sure what to search for in google. I need to know how to convert from LINESTRING (40.619605 -73.9584046, ... to something like LINESTRING (4883.179 10736.259, 4924.922 10811.716)
preferred language is python, thanks.
The format ONE uses is subset of the standard WKT format. See details in the WKTReader class and ReadMe.
The coordinates used in the WKT input files are in reference to the simulation world coordinates. You can open your source map file with a WKT editor (e.g., OpenJUMP) and translate the coordinates so that they’re all positive and that could be enough.

How to write projection info into netcdf file use xarray?

I need to use xarray to write the projection information into the netcdf file so that Iris can directly obtain the projection information when reading it.
We know that there are many projection s in cartopy, such as equal latitude and longitude projection, Lambert projection, etc. How to write this information into netcdf file? Is it similar to an epsg string?
For Iris, you most likely want to encode the grid projection information in a grid_mapping attribute on the data variables according to the Climate and Forecasting netCDF Conventions.

Strange coordinate units

I received a .gdb file that I need to do analysis on. This is an ESRI file, but I don't have access to any ESRI products. I opened it in R using the "rgdal" package, but the coordinates it displays seem very off.
For example, (-9288065, 4604652) should map to Kentucky. My initial thought was that there are missing decimals, so it should be -92.88 and -46.04, but this maps to somewhere north of Kentucky, which is wrong.
Do these coordinate units look familiar? How might I convert them to latitude and longitude?
Solved with help from #camille.
For future users:
library(rgdal)
library(raster)
myFeatureClass<-readOGR('your_data_here')
#checks the projection type
sp::proj4string(myFeatureClass)
#convert projection to longlat
final_data <- as.data.frame(spTransform(myFeatureClass, CRS("+proj=longlat +datum=WGS84")))

Create buffer around spatial data in R

I have a spatial dataset of shopping centers that I would like to create buffers around in R.
I think these packages will be useful:
require(maptools)
require(geosphere)
I was able to do so for a set of coordinates, but not for spatial data. The code looks like this:
coordinates(locs) <- c("Longitude", "Latitude") # set spatial coordinates
fivekm <- cbind(coordinates(locs), X=rowSums(distm (coordinates(locs)[,1:2], fun = distHaversine) / 1000 <= 5)) # number of points within 5 km
But I don't know what function/package to use for a set of polygons. Can someone please advise on the function (or code) and I will go from there?
Thanks!
In library rgeos, there is the gBuffer function that works with SpatialPoints or SpatialPolygons.
The width parameter allows to set the distance to which you want to buffer. However, be careful, this distance is in the scale of the coordinates system used. Thus, in degrees and not in meters with non-projected data. As suggested by #Ege Rubak, you will have to project your data with spTransform first (be sure to use the appropriate CRS according to your location).
As for now, rgeos library works with library sp, but not (yet?) with the recent sf.
I think the only option at the moment is to project your longitude and latitude points to a flat map and then do everything there. As far as I know there are no packages for doing polygonal geometry on the sphere yet (I'm working on one, but there is no ETA).
Projection used to be done with spTransform from the sp package, but now it may be more convenient to use the more modern simple features package sf which has the function st_transform. The vignette https://cran.r-project.org/web/packages/sf/vignettes/sf1.html has a section called "Coordinate reference systems and transformations" to help you with this part. The buffering is described in the section "Geometrical operations".
The two previous post have covered the details but I thought it might be helpful to provide a workflow. This is assuming you have you are using points of lat and long. What is your original spatial data format?
Convert your coordinates into a Spatial Points Dataframe SpatialPointsDataFrame and assign it a geographic CRS (proj4) that matches your coordinate data (probably WGS84)
Change the projection to a local projected CRS with preferred units
Apply buffer to spatial point data frame, the width will now be in more usable units

Combining geographic layers with different projections in R

EDIT: I have reworded the title question slightly, and adjusted the text to respond to the comment by #DWin.
Combining geographic layers that are projected and not projected can be challenging. Often, it seems, some transformation is necessary, as geographic layers come from different products and publishers.
I am aware that R has several tools to perform geographic transformations. For example:
For objects of class Spatial* in the sp package, the spTransform() function in the rgdal package can be used; and,
For objects of class Raster* in the raster package, the projectRaster() function can be used.
Here is a specific task that I would like to accomplish in R: Transform to UTM grid Zone 15N (Datum: NAD83) a polygons layer describing lakes in a UTM grid Zone 15N (Datum: NAD27) projection (this is in an ESRI shapefile format).
The useful thing here is the epsg database included in rgdal.
epsgs = make_EPSG()
subset(epsgs,grepl("15N",epsgs$note))
[etc]
code
2703 26715 # NAD27 / UTM zone 15N [etc]
2851 26915 # NAD83 / UTM zone 15N [etc]
[etc]
Those codes are what you need in spTransform. If your lakes are in a shapefile with that NAD27 projection, then:
require(maptools)
lakes = readShapeSpatial("lakes.shp")
proj4string(lakes)=CRS("+init=epsg:26715")
should give you the lakes as supplied (note I dont think readShapeSpatial will read a .prj file with a shapefile set, so I've set it here explicitly)
Now to convert to NAD83 datum version of UTM zone 15N:
lakes83 = spTransform(lakes,CRS("+init=epsg:26915"))
Rasters are a bit trickier since they generally involve a warp so that you end up with a regular grid in your projected coordinate system - you can't just transform the coordinates of the corners...

Resources