आर

2011-10-18 13 views
7

का उपयोग कर एक केएमएल फ़ाइल कैसे बनाएं I कुछ मानचित्र बिंदु डेटा (अक्षांश और देशांतर मान) प्राप्त करने के लिए मैंने एक आर स्क्रिप्ट लिखी है। मैं उन्हें आर में साजिश करने और उन्हें कल्पना करने में सक्षम हूं। लेकिन अब मैं इस डेटा से एक केएमएल फाइल जेनरेट करना चाहता हूं और Google धरती का उपयोग करके देखना चाहता हूं। ताकि मैं इसे सहकर्मियों के साथ साझा कर सकूं और वे इसे Google धरती पर भी देख सकें।आर

ऐसा करने के लिए सबसे अच्छी विधि/पैकेज क्या है?

उत्तर

14

rgdal पैकेज में writeOGR फ़ंक्शन देखें। यहाँ एक सरल उदाहरण है:

library("sp") 
library("rgdal") 
data(meuse) 
coordinates(meuse) <- c("x", "y") 
proj4string(meuse) <- CRS("+init=epsg:28992") 
meuse_ll <- spTransform(meuse, CRS("+proj=longlat +datum=WGS84")) 
writeOGR(meuse_ll["zinc"], "meuse.kml", layer="zinc", driver="KML") 

वस्तुओं का निर्यात किया SpatialPointsDataFrame, SpatialLinesDataFrame, या SpatialPolygonsDataFrame वस्तुओं रहे हैं के रूप में sp पैकेज में परिभाषित किया।

R> class(meuse) 
[1] "SpatialPointsDataFrame" 
attr(,"package") 
[1] "sp" 

एम एल ड्राइवर के साथ लिखने के लिए, ध्यान दें कि geometries गृहीत WGS84 साथ भौगोलिक निर्देशांक में होना चाहिए।

0

यदि आप आर के बाहर कदम उठाने के इच्छुक हैं, तो डीएनआरजीर्मिन नामक एक निशुल्क प्रोग्राम एक अल्पविराम से अलग फ़ाइल को .txt के रूप में ले जा सकता है और इसे Google धरती में आयात के लिए .kml में परिवर्तित कर सकता है।

आप इसे यहाँ पा सकते हैं:

http://www.dnr.state.mn.us/mis/gis/tools/arcview/extensions/DNRGarmin/DNRGarmin.html

तो आर में

:

my.geo.data <- all.my.data[ c("unique.id", "lats", "longs")] 

write.csv(my.geo.data, file = "myGeoData.txt") 

खुला DNRGarmin,

फ़ाइल -> से लोड -> फ़ाइल -> myGeoData.txt फिर, फ़ाइल -> सेव करें -> फ़ाइल -> myGeoData.kml

@ आरसीएस की सलाह फिर से: WGS84 भी इस उत्तर के लिए लागू होता है।

गुड लक

0

आप/अपने सहकर्मियों पता QGIS हैं, तो यह Google धरती में डेटा प्रदर्शित करने के लिए एक बहुत अच्छा तरीका है। क्यूजीआईएस में Google धरती को बेस मैप के रूप में दिखाने की सुविधा है और फिर आप अपना स्थानिक डेटा खोल सकते हैं और इसे बेस मैप पर प्रदर्शित किया जाएगा। निश्चित रूप से यह आपके डेटा को सही ढंग से प्रक्षेपित करने की आवश्यकता है क्योंकि आरसीएस कहता है।

यहाँ आप maptools पैकेज और स्थानिक अंक पैकेज का उपयोग करने वाली आकृति फ़ाइल के रूप में अपने अंक का निर्यात करने की जरूरत है:

library(maptools) 
library(sp) 

## define projection 
myProjection <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" 

## your points in format dataframe 
coordinates.df <- as.data.frame(MyCoordinates) 

## the number of points you have as dataframe 
number <- as.data.frame(NumberOfPoints) 

## convert points to Spatial Points Dataframe 
myPoints.spdf <- SpatialPointsDataFrame(coordinates.df, number, proj4string = CRS(myProjection)) 

## save shapefile 
writeSpatialShape(myPoints.spdf, "MyPointsName") 

आपका अंक अब QGIS में खोला जा सकता और Google धरती में प्रदर्शित किया। क्यूजीआईएस में यदि आवश्यक हो तो आपका डेटा आसानी से kmz फ़ाइल के रूप में सहेजा जा सकता है।

2

मुझे लगता है कि plotKML पैकेज का भी उल्लेख करने लायक है।

हालांकि, सहकर्मियों के बीच आसान साझा करने के लिए मुझे पैकेज leaflet पैकेज पर आधारित दिलचस्प पाया गया। कोई पृष्ठभूमि मानचित्र के लिए विभिन्न विकल्पों के साथ HTML दस्तावेज़ के रूप में मानचित्र को सहेज सकता है; Google धरती की आवश्यकता नहीं है और HTML मानचित्र आपके ब्राउज़र पर चलाएगा।

कुछ उदाहरण: plotKMLhere साथ

library(sp) 
library(rgdal) 
library(raster) 
library(plotKML) 
library(mapview) 

# A SpatialPointsDataFrame example 
data(meuse) 
coordinates(meuse) <- ~x+y 
proj4string(meuse) <- CRS("+init=epsg:28992") # CRS Amersfoort (Netherlands) 
# make a KML file from SpatialPointsDataFrame object 
# will get a warning like "Reprojecting to +proj=longlat +datum=WGS84 ..." 
# as it is expected to work with geographical coordinates with datum=WGS84, 
# but seems that it takes care of the reprojecting. 
plotKML::kml(meuse, 
      file.name = "meuse_cadium.kml", 
      points_names = meuse$cadmium, 
      colour = "#FF0000", 
      alpha  = 0.6, 
      size  = 1, 
      shape  = "http://maps.google.com/mapfiles/kml/pal2/icon18.png") 
# Or, an easy to make interactive map with mapView() 
mapView(meuse) 

# A RasterLayer example 
data(meuse.grid) 
gridded(meuse.grid) <- ~x+y 
proj4string(meuse.grid) <- CRS("+init=epsg:28992") 
dist_rst <- raster(meuse.grid["dist"]) 
# make a KML file from RasterLayer object 
plotKML::kml(dist_rst, 
      file.name = "dist_rst.kml", 
      colour_scale = SAGA_pal[[1]]) 
# Or, easy to make interactive map with mapView() - display raster and add the points 
mapView(dist_rst, legend=TRUE) + meuse 
# However, note that for bigger raster datasets mapView() might reduce from resolution 

अधिक उदाहरण, एक ट्यूटोरियल here साथ। mapview के लिए, एक परिचय here पाया जा सकता है।