Is it possible to plot/map xml data from arc GIS in R? I have an XML file with a basemap I would like to map in R.
I dont know how to add my XML file to my question but if someone could show me how to plot using this type of file that would be awesome. I usually make my maps in r using ggplot and geom_sf.
#How I loaded my XML file into r
# Load the package required to read XML files.
library("XML")
# Also load the other required package.
library("methods")
# Give the input file name to the function.
result <- xmlParse(file = "Grey background.xml")
# Print the result.
print(result)
Related
I am using this following code for plotting the trajectories...........
library(openair)
load("GDASNDL1000m.Rdata")
trajLevel(traj,method="hexbin",col="jet",xbin=40,parameters=NULL,
orientation=c(90,0,0),projection="mercator")
result https://github.com/adeckmyn/maps/files/2667752/GDASNDL1000m.zip
Here, I would like to change the base world map with my own shape file.
my shape file is follows....
z1=maptools::readShapePoly("/home/sateeshm/shapefiles/ncmrwf/india_map")
library(maps)
map(z1)
https://github.com/adeckmyn/maps/files/2667336/World-India.zip
#
Now, the actual question is how to link z1 to trajLevel?
To avoid the hard-coded call to "world" in openair, you wil have to create a new world database in the same file based format as that of the "maps" package.
Probably the simplest way to do this, is to use the mapMaker package. This package is not on CRAN but can be found on github. It is the package I used to create the standard world map. The documentation is minimal, but if you don't care about polygon names etc, you can create a "quick and dirty" world map as follows:
# get your new map as a simple list of polygons (or lines)
z1=maps::map(maptools::readShapePoly("india_map"), plot=FALSE)
# create internal representation
z2=mapMaker::map.make(z1)
# write binary files:
mapMaker::map.export.bin(z2, "/my/path/to/world")
# To make map() call this new database:
library(maps)
worldMapEnv="MYMAP"
Sys.setenv("MYMAP"="/my/path/to/") # don't add the "world" !
now map("world") will draw your version of the world map.
Im looking into how to handle .h5 (hdf) VIIRS DNB raster data in R. I would like to plot it or export it as a geotiff.
So far I am able to read in the file with
hdf<- h5file("mypath/GDNBO-SVDNB_npp_d20171101_t0110370_e0116174_b31151_c20180208224859630066_nobc_ops.h5", mode = "r")
But I cannot figure out how to access the "radiance" band, let alone plot it. I have read the "h5" package documentation without any progress..
As another option I have tried to export the h5 file to geotiff with
sds <- get_subdatasets("subset_1_d20171101_t0110370.h5")
gdal_translate(sds[17], dst_dataset = "radiance.tif", overwrite=T) #subset 17 is the radiance band i need
however the file has lost its geolocation during the transformation, when the geotiff is opened in e.g. QGIS, it doesnt have any location or projection.
Anyone knows how to deal with these type of files in R?
Hi I am trying to read and plot on a custom shape file in R which is not a map.
This is the code I use and the error I get in return:
library(rgdal)
mySHP<- choose.files()
myFile<- readOGR(mySHP)
Error in ogrListLayers(dsn = dsn) : Cannot open data source
If your file is a shapefile, you need to specify the dsn which is the directory where is saved the shapefile and layer which is the name of the shapefile without the extension. You cannot really do it with choose.files. At least not that simply.
myFile <- readOGR(dsn='path.to.folder', layer='nameOfShapefile')
I have downloaded a dataset that is supposed to be a global map of freezing and thawing indices. Unfortunately I cannot uploaded or view it as a raster in R. Does anyone know how to convert this type of file to a .bil file?
I can load the file using: dat<- read.delim('freez.dat', header = F)
But I cannot get this to plot as a traditional raster.
Any input is appreciated.
I have a script to create a randomly distributed square polygons in KML format which takes in shapefile with a single polygon as an input which works absolutely well. The problem arise when I tried to create the user defined function out of it. I used readShapePoly() function to read the shapefile and it works well when used out of the function. But when the function is created in which shapefile should be given as an input, it simply wont take. It shows this error message
Error in getinfo.shape(filen) : Error opening SHP file
I avoid writing extensions and I do have all the extension files to create the shapefile.
Part of the script to read the shapefile using it as the input file:
library(maptools)
library(sp)
library(ggplot2)
Polytokml <- function(shapefile_name){
###Input Files
file1 <- "shapefile_name"
Shape_file <- readShapePoly(file1) #requires maptools
return(Shape_file)
}
The function is created but it doesn't work if the function is called.
>Polytokml(HKH.shp)
Error in getinfo.shape(filen) : Error opening SHP file
This works well out of the function.
###Input Files
file1 <- "shapefile.shp"
Shape_file <- readShapePoly(file1) #requires maptools
This is just an example out of the whole script in which different arguments are taken as an input. So just to make things simple I have added script to read the shapefile which has been a problem now. Do let me know if it is not clear.
Thank you so much in advance :)