convert .shp file to map with jvectormap-1.2.2 - dictionary

I follow this document and this question.
I have downloaded ne_10m_admin_1_states_provinces files but I can not find
country_code_index (for Iran Or other country) in it.
I use this command in ubuntu command line :
ogrinfo ne_10m_admin_1_states_provinces.dbf -al > Out.txt
out.txt's content is :
How to find --country_code_index AND --country_name_index ?

Go through Map-converter-notes which has very good information about all the steps required to generate a new map from public data.
Linux users can install a very handy tool SAGA-GIS to generate required shape file and then use converter.py to generate map to use with jvectormap.com plugin.
country_code_index is the index of attribute which will be used as code name for specific region on map and country_name_index is the attribute which will be shown as label of region on map. Attributes chosen for these should have unique values in map data table.

Related

How to edit cells Shapefile in R?

I downloaded a shapefile of the world map from gadm, however, there are typos that happen with importing the shape file. For example "Aland" shows up as "Ã…land" in the shapefile. There are handful of countries I want to make changes to.
world map shapefile, the one that says "You can also download this version as six separate layers (one for each level of subdivision/aggregation), as a geopackage database or as shapefiles" :https://gadm.org/download_world.html
I imported the shapefile using:
worldmap <- readOGR("file/gadm36_0.shp")
I tried using the following code:
levels(wordlmap$NAME_0)[5] <- "Aland"
However I got this message:
Error in `levels<-`(`*tmp*`, value = c(NA, NA, NA, NA, "Aland")) :
factor level [2] is duplicated
Could you suggest how this code can be made better or an alternative.Thanks in advance
Since you did not provide a shapefile, I just worked with a publicly-available shapefile of Indian states. The long and short of it is to use the sf package. It loads shapefiles as (quasi) dataframes--with the longitudes and latitudes stored in the geometry variable. Then, you should be in familiar territory. Here is some code to change a state name variable:
# clear environment
rm(list=ls(all=TRUE))
# let's take admin 1 (states)
# note: already in WGS84 format
library(sf)
india_shape <- st_read("india_shape/gadm36_IND_1.shp", stringsAsFactors=FALSE)
# Let's pick something to change (state name)
> india_shape$NAME_1[1]
[1] "Andaman and Nicobar"
# Now change it
> india_shape$NAME_1[1] <- "New State Name"
> india_shape$NAME_1[1]
[1] "New State Name"
I can tell you a few things about how I manage those shape files downloaded from, www.gadm.org site.
First, a shape file has several other related files that do not have the .shp extension. These files must remain together in the same folder. All these files are included in the shape zip file from the gadm website.
The rgdal package provides the, readOGR() function. This function is normally in the form: readOGR(dsn = " ", layer = " " )
The, dsn is "data source name". Use quotes.
The, layer is the name of shape file without the .shp extension. Use quotes.
Proper file management is required to make things work and to maintain good file management. I already have a USA folder within my dataset folder.
I just downloaded the gadm USA shape file. So first, I will add a new folder, named USA_map, in the USA folder. And also create a new folder named, data in this new USA_map folder.
C:/python/datasets/usa/usa_map/data # usa_map/data are new
Copy the downloaded gadm36_USA_shp.zip from the "download" folder and paste into the new "USA_map" folder. Then, open the GADM zip folder and extract the entire contents of the zip folder into the new "data" folder. Then the zip file can new be deleted because all the files have been copied into the "data" folder. All's done and ready.
Now use the readOGR() function to read the shape file and assign to new variable, called usmap
usmap <- readOGR(dsn = "c:/python/datasets/USA/USA_map/data", layer = "gadm36_USA_1")
The trick is to follow the correct file management so the readOGR() function works as designed.
Next, you need to learn how to navigate through this type of data.
If there is more than one polygon with the same wrong name, you can make like that :
w <- length(wordlmap)
for (i in 1:w){
if (wordlmap$NAME_0[i] == "Ã…land") {
wordlmap$NAME_0[i] <- "Aland"
}}

How can I open a .json.gz format file in R?

I am a Data Science student writing my thesis using product review data. However, this is packed in a .gz file.
The file name when downloaded is 'xxx.json.gz' and when I look into the properties it says the type of file is gz Archive (.gz), Opens with 7-Zip File Manager.
I found the following code:
z <- gzfile("xxx.json.gz")
data = read.csv(z)
But the object 'data' is now a list. All columns are factors and the column with the review text is not right at all. I think the read.csv() part is wrong since it's supposed to be a json file.
Does anyone have solution? I also have the URL address of the data if that's better to use: http://deepyeti.ucsd.edu/jianmo/amazon/categoryFilesSmall/Electronics_5.json.gz
Loading it at the moment, I got 5,152,500 records right now, it is probably the review text that is clogging it up
library(jsonlite)
happy_data <-stream_in(
gzcon(
url("http://deepyeti.ucsd.edu/jianmo/amazon/categoryFilesSmall/Electronics_5.json.gz")
)
)

How to generate a graph file?

Is there a way to generate valid graph files like simple-leuven.dot or graphs of other cities available on Rinsim?
We'd like to find a fast way to generate directed cyclic graphs with various geometries.
The Leuven map was downloaded from OpenStreetMap as an XML file and then converted to dot using a script. The code that was used for this has been removed from the main RinSim branch as it is very fragile. You can still find the code in the repository though, see OSM.java in v2.3.3.
A few other city maps have been created using this code and they can be found on this website.
Apparently, the code in OSM.java has been refactored into a project in this github repo osm-to-dot-converter. All you have to do is to create a main method to convert an XML openstreetmap file (.osm). For instance:
public static void main(String[] args) {
OsmConverter myOsmConverter = new OsmConverter();
myOsmConverter.setOutputDir("/home/username/");
myOsmConverter.withOutputName("cityname.dot");
// I am not sure what pruning is used for,
// you can comment out the next line if you do not understand what it is used for
myOsmConverter.withPruner(new RoundAboutPruner(1), new CenterPruner());
// the XML file is to be feed here
myOsmConverter.convert("/home/username/cityname.osm");
}

adding custom map to maps package

I want to be able to use map.where function on a map that is not currently available in the MapEnv in the maps package--such as these maps of Brazil: http://www.usp.br/nereus/?dados=brasil. They go into a more granular level than what is available in the maps package.
Is there anyway to add them to the package data so that they can be used by maps.where?
Yes, it is usually possible to load shp files into map(). You will need extra packages to read the shp files first, though. Also, you will have to know the name of the field that names the polygons.
For instance, using one of the maps from your link:
> ufebrasil <- rgdal::readOGR("UFEBRASIL.shp")
> names(ufebrasil)
[1] "ID" "CD_GEOCODU" "NM_ESTADO" "NM_REGIAO"
> mymap=maps::SpatialPolygons2map(ufebrasil, namefield="NM_ESTADO")
> map.where(mymap, -48.6, -26.46)
[1] "SANTA CATARINA:1"
You can also simply call
mymap=maps::map(ufebrasil, namefield="NM_ESTADO")
to plot a map and give the same map data as above (map() will call SpatialPolygons2map automatically if necessary).

save file in XYZ format as vector (GML or shp)

I am using QGIS software. I would like to show value of each raster cell as label.
My idea (I don't know any plugin or any functionality from QGIS which allow to it easier) is to export raster using gdal2xyz.py into coordinates-value format and then save it as vector (GML or shapefile). For this second task, I try to use
*gdal_polygonize.py:*
gdal_polygonize.py rainfXYZ.txt rainf.shp Creating output rainf.shp of
format GML.
0...10...20...30...40...50...60...70...80...90...100 - done.
unfortunately I am unable to load created file (even if I change the extension to .gml)
ogr2ogr tool don't even recognize this format.
yes - sorry I forgot to add such information.
In general after preparing CSV file (using gdal2xyz.py with -csv option),
I need to add one line at begining of it:
"Longitude,Latitude,Value" (without the quotes)
Then I need to create a VRT file which contain
*> <OGRVRTDataSource>
> <OGRVRTLayer name="Shapefile_name">
> <SrcDataSource>Shapefile_name.csv</SrcDataSource>
> <GeometryType>wkbPoint</GeometryType>
>
> <GeometryField encoding="PointFromColumns" x="Longitude"
> y="Latitude"/>
> </OGRVRTLayer> </OGRVRTDataSource>*
Run the command "ogr2ogr -select Value Shapefile_name.shp Shapefile_name.vrt". I got the file evap_OBC.shp and two other associated files.
For the sake of archive completeness, this question has also been asked on GDAL mailing list as thread save raster as point-vector file. It seems Chaitanya provided solution for it.

Resources