Shapefile has multiple "maps" in R - shapefile

I am fairly new to using shapefiles in R.
I downloaded a shapefile of Africa and imported it into R.
africa<-st_read(paste0(shape_file_directory, "africa_map/afr_g2014_2013_0.shp"))
I then wanted to check out how the shapefile looks.
plot(africa)
Somehow the shapefiles includes multiple maps of Africa?:
shapefile maps
I just want a simple outline of Africa and its countries.
Sorry if this is a trivial question and let me know if you need any more info.
Thanks.

By default plot.sf will create one plot for each attribute (non-geometry column) in a spatial data frame. You can choose a single attribute to plot or show just the geometry by changing the data you pass to plot. See this vignette for details:
https://r-spatial.github.io/sf/articles/sf5.html

Related

Power BI maps: something in between ArcGIS Maps and Shape Maps

I'm trying to create a colored heat map on some polygons (originally a .kmz file that I converted to TopoJSON - .json with mapshaper.org) and overlay on them a few coordinate points.
I tried first with ArcGis: I used Longitude and Latitude to visualize the location of certain objects and then I overlapped a layer I found online on ArcGis (that's the same I would like to use). The problem is that I cannot color the polygons in this layer and it seems not possible (https://community.powerbi.com/t5/Desktop/ArcGIS-geographic-ID-mapped-onto-a-polygon-layer/m-p/339432). I cannot even upload the data on ArcGis because the data are private company data.
Then I tried with Shape Map: I uploaded the TopoJson and colored them with the data I had associated with these zones, but I cannot find a way to display the objects with coordinates on top of them.
Do you have any suggestion on what can I do? or is it an impossible task at the moment?
I can show here the results (the dots with the coordinates are in the center of the image on the left):
Here there are some mock up data and the PBI file I created: https://drive.google.com/open?id=1rloRkCdi0-M-4ljPdOU9cxg_KpcU5GnT
Pay attention to data format: I converted some of them during the import.
Thanks, any help is appreciated.
It looks like this is not possible to be achieved in Power BI at the moment:
https://community.powerbi.com/t5/Desktop/Shape-Map-ArcGIS-Map-can-I-combine-them/m-p/838523#M402722

How to Create Shapfile through arcpy with a user input MGRS coordinate

Using Python 2.7.10, is it possible to get user input of an MGRS coordinate and create a shapefile from that coordinate? I am finding ways to work with LAT/LON coordinates but not much from MGRS. I am sure someone has done this before, if you could please share your code, it would be greatly appreciated.
I figured it out, sorry but I am just learning how to use python and its taking me a while to figure out what to search for.
If there is an easier way of doing this I would like to know for future though.
create a GDB
create a table in the GDB
add field to the GDB with MGRS title
add cursor, adds a row to the table
populate the MGRS coordinate received from user into MGRS column
Convert coordinate from MGRS to Lat/Lon, this creates a .shp while also adding the Lat/Lon to the attribute table for future if required.

how to query the database to return all zip codes with a given distance (ie 5 miles) from a given zip code using geopy

Hi frens I am using geopy to calculate the latitude and longitude. Now I want to get the list of areas given distance from a zipcode.How to get that?
Well, as I can see, geopy doesn't have any built-in capability to get a list of areas around some coordinates.
But you can use a workaround. Take your geocode and calculate coordinates (latitue and longitude). Then imagine a grid on the map with a cell size equal to area of the smallest one you need to find around your location.
Use geopy to get an area name belonging to the each cell corner of your grid. Is that ok for you? It will get you some kind of approximation because a grid is not a circle and you may miss some small areas. But I think in most cases the solution will work fine.
It is much easier to locate zipcodes inside a rectangle than in a circle so I would recommend that you approximate your problem by looking for zipcodes inside a given rectangle.
Here are answers to the question of how to get list of zipcodes in given polygone: Find zipcodes inside polygon shape using google maps api
Summary
You need geometry for each zipcode. Once you have that you need to be able to query it using database that supports geoquery. One such database is Google's Fusion Table and there is already a geometry data table for zipcodes available here: https://www.google.com/fusiontables/DataSource?docid=1AxB511DayCdtmyBuYOIPHIe_WM9iG87Q3jKh6EQ#rows:id=1
Here's the sample query for Fusion Table data.
Another approach is server side code using PHP and CSV data. Here's live demo: http://daim.snm.ku.dk/demo/zip/. The page also has download for code.
If you use any of above technique please make sure to upvote answers of original authors :).

Turn on boundary layer if more than one record in the map extent/ layout view?

Anyone have any ideas as to how can I automate the process where if there is more than one administrative boundary area in the map extent to turn on that boundary layer for map labeling using a python script from within a map document?
For instance, if there are multiple county boundaries within the visible map extent (say the area of interest overlaps two counties) to turn on the boundary layer? I do not want to tabulate intersection on the area of interest as it does not cover the entire layout. In effect, if only one county is displayed in the map extent/layout, do not turn on the county layer. However, if it does display more than one county, turn on the county layer for display in the map extent/layout. I am trying to automate map production and am stuck on this one as I am “tabulating the intersection” of the map/layout extent, not a specific feature class.
Make sense? Thanks for any and all guidance as to how to approach this.
Using ArcGIS 10.1 SP1 Advanced
If discovered a way yo do this. I snagged an script that creates a polygon from the current map extent. I then performed a tabulate intersection on the boundary using this polygon. If the length of the resulting table was larger than 1, I turned the layer on.
Create polygon from map extent script link

How can I get Google Charts to display multiple colors in a scatter chart?

I would like to display multiple colors (and potentially shapes and sizes) of data points in a Google Chart scatter chart. Does anyone have an example of how to do so?
I answered my own question after waiting SECONDS for an answer here :-)
You can indeed have different colors for different data elements. For example:
http://chart.apis.google.com/chart?chs=300x200&cht=s&chd=t:1,2,3|6,5,4&chds=1,3,0,10&chxt=x,y&chxl=0:|0|1|2|1:|0|10&chm=d,ff0000,0,0,8,0|a,ff8080,0,1,42,0|c,ffff00,0,2,16,0
It's the chm= that does the magic. I was trying to have multiple chm= statements. You need to have just one, but with multiple descriptions separated by vertical bars.
You can only use one dataset in a scatter plot, thus only one color.
http://code.google.com/apis/chart/#scatter_plot
From the API description:
Scatter plots use multiple data sets differently than other chart types. You can only show one data set in a scatter plot.
You could effectively fake a multi-color scatter plot by using a line plot with white lines and colored shape markers at the points you want to display.
Here's another example: twitter charts. I'm hoping to do the same thing. Need to find out how to do the concentric circles.