geoviews/geopandas/shapely problem displaying polygons from a shapefile - shapely

I am trying to overlay a shapefile representing the range of Coast Redwoods onto some other data I'm processing in geoviews. I can successfully plot the data using cartopy and matplotlib. GeoPandas reads the shapefile, but passing the GeoDataFrame or individual shapely polygons to gv.Shape (as in the geoviews user guide under "Shape") consistently results in
AttributeError: 'list' object has no attribute 'xy'
I am not sure whether the problem is in Shapely or in Geoviews. I suspect geoviews because geopandas is able to reproject and plot the polygons.
I've put up a notebook demonstrating the problem and providing the shapefile.
Any help or ideas much appreciated.

I was having the same issue, then i went ahead and converted my GeoDataFrame to EPSG:4326 as follows:
projected_df = original_df.to_crs('EPSG:4326')
Originally I was in EPSG:4269 (Albers Equal Area) and thought adding that to an Albers Equal Area projection would work but I think you need to start your data with EPSG:4326 and then work with projections with Geoviews.
Let me know if that does the trick.

Related

How to turn a spatial plot in R into an ArcGIS layer

So I hope I can clearly communicate my issue. Since I'm fairly new to R and ArcGIS I may miss some obvious things.
Basically, I'm using R to process spatial data to make a canopy height model and detect tree tops. That parts fine. I then make a watershed segment plot using forestTools package, and visually it looks great, but how do I export that as a file I can add into ArcGIS?
I'll copy some of the code that goes into what I'm discussing.
Basically, I just followed this guide's supplemental material to get the tree detection https://www.degruyter.com/document/doi/10.1515/geo-2020-0290/html?lang=en.
With that done, I then used the forestTools package to creat an interesting segmentation polygon grid on the map. https://www.rdocumentation.org/packages/ForestTools/versions/0.2.5/topics/mcws
This is quickly the plotting code to get visualized what I want.
[1]: https://i.stack.imgur.com/7Y0EF.png
This is what the map looks like with those plotted.
[2]: https://i.stack.imgur.com/Kdfl6.png
The layer that I want to bring solo to ArcGIS is that last plot the mcws one. I'll show a pic of that as well here.
[3]: https://i.stack.imgur.com/3PKfk.png
Is there a way that I can export that as a .shp or .tif?
Any help would be wonderful and much appreciated!
Nvmd I figured it out.
What you have to do is use the Raster package to export a shapefile.
raster::shapefile(site2_ttops,"Products/site2plot_ttops.shp")

Why is my GIS Shapefile (CRS 4326) not viewed from directly above?

I have loaded two shapefiles into Netlogo. One shapefile's original projection was 4326 (osmdata) and one was originally 28992 (Dutch government data) which was st_transformed(4326) in R. When I load them into Netlogo, it does not display the shapefile directly from above, which it does do from R ggplot
Why is this and how do I get it viewed from above?
It was solved by using gis:set-world-envelope-ds instead of gis:set-world-envelope

Map projection from epsg:4326 to epsg=3857 and Bering strait problem

I am using python bokeh to project data over a world map.
I have a geopandas geopdwd init with crs="epsg:4326" and I want to project it to a mercator world map using bokeh tile. Then I fill countries have selected by some color.
Basicaly I need to convert my geopandas geometry (an epsg:4326) to epsg=3857 one.
For this purpose I do:
geopdwd = geopdwd.to_crs(epsg=3857)
But as you can see I have a problem with the russian part and specially with the Bering strait. It is colorized in the wrong part ...
I thing I need to force it to the right part of my world map.
Do have any idea to deal with that problem ? Do I need to use an other projection ?
For interested people I have solved the problem, have a look to my Bokeh thread : https://discourse.bokeh.org/t/bokeh-tile-antimeridian-problem/6978

Issue with coordinate projection for detecting spatial autocorrelation in R

We have a dataset that contains latitude and longitude coordinates, as well as attribute information, each in its own separate column, stored as numeric. These coordinates have been geocoded based on the geographic coordinate system WGS 1984.
We know that we have significant spatial autocorrelation in our data, which we are hoping to visualize in a bubble plot using the “sp” package. We are modeling our example off of others online, such as here: https://beckmw.wordpress.com/2013/01/07/breaking-the-rules-with-spatial-correlation/ . However, when we try to use the coordinates command within "sp", we keep getting an error message:
Code example:
coords <- data.frame(lead$X, lead$Y)
coordinates(coords) <- c("lead6.X","lead6.Y")
Error in if (nchar(projargs) == 0) projargs <- as.character(NA) missing value where TRUE/FALSE needed
We can't load our direct code because it's sensitive and hosted on a virtual environment without access to the internet. Does anyone have ideas for why this might be happening? We've looked into the proj4 package but can't figure out how to specify a projection system (or is that even the error that we are getting?). If anyone knows of any other packages in R or ways to visualize spatial autocorrelation, those would be much appreciated too.
Your code is a bit "strange": seems you are trying to build a dataset containing only coordinates. AFAIU, you may need something in this line :
data <- data.frame(lead$X, lead$Y, lead$Z)
,with lead$Z corresponding to a generic "variable" you want to inspect, then
coordinates(data) <- c('X','Y')`
proj4string(data) <- "+init=epsg:4326"
, which should give you a proper "SpatialPointsDataframe" with lat-lon WGS84 geographic coordinates (the first line could be also dropped, and you'll keep all variables in the data of the spatialpointsdataframe).
HTH

Adding Boundaries to Spatial Polygons Object

I have the following SpatialPolygonsDataFrame.
require(raster)
usa <- getData('GADM', country='USA', level=2)
metro <- subset(usa, NAME_1=="Nebraska" & NAME_2 %in% c("Dodge","Douglas","Sarpy","Washington"))
plot(metro)
I would like to be able to replicate the following map boundaries (defined by the colors):
Does anyone know a good plan of attack? I realize this is a somewhat manual process. I have already downloaded all US Census files that are of a more detailed geography. I was hoping that a more detailed level of geography could be aggregated to answer the above question, but unfortunately the districts do not line up the same.
Is there a R function already out there that would be helpful in assisting this manual process? At the very minimum, I would like to be able to leverage the perimeter of the 4-county area.
Use writeOGR from the rgdal package to create a shapefile of your metro object. Then install QGIS (http://www.qgis.org/), a free and open-source GIS, and load the shapefile as a new layer.
Then you can edit the layer, add new polygons, edit lines etc, then save as a shapefile to read back into R.
Additionally, you may be able to "georeference" your image (by identifying known lat-long points on the image) and load that into QGIS as a raster layer. That makes it easier to digitise your new areas. All you need for that is a few lat-long coordinates of specific points, such as the corners of polygons or line intersections, and then QGIS has a georeferencing plugin that can do it.
I don't think you'll find any R code as suitable for digitising new geometries over an image as good as QGIS.
After half an hour (and twenty years experience, not all of which you'll need) I've got this:
I didn't precisely digitise your new boundaries though, just roughly for speed. That QGIS screen cap shows the five coloured areas under the four metro areas.
Step one was georeferencing. This screengrab shows how the PNG has been georeferenced - the red line is the metro area shapefile drawn with transparency over the PNG after the PNG has been converted to a GeoTIFF by matching control points.
Step two was then using QGIS editing tools to split, join, and create new polygons. Then I just coloured them and added labelling to pretty it up.
I could probably bundle these files all up for you to neaten, but it really doesn't take that long and you'll learn a lot from doing it. Also, this is probably a gis.stackexchange.com question...

Resources