如何绘制shapefile并提取lat/lng coords,以便在Google Maps上绘制多边形?
http://www2.census.gov/cgi-bin/shapefiles/national-files
我在这里问这个问题:
http://groups.google.com/group/Google-Maps-API/browse_thread/thread/18763b4b0cb996c7
他们告诉我该怎么做,但不是如何做到这一点= P.
谢谢!
我有一些我想在Google地图图块上绘制的shapefile.最有效的方法是什么?一条路径可能是使用pkg RgoogleMaps,但是,我仍然不清楚如何执行此操作.我假设使用PlotonStaticMap重新格式化shapefile数据
给定一个shapefile,我如何塑造和使用数据文件,以便能够使用与shapefile中的形状区域对应的标识符来绘制专题图?
#Download English Government Office Network Regions (GOR) from:
#http://www.sharegeo.ac.uk/handle/10672/50
tmp_dir = tempdir()
url_data = "http://www.sharegeo.ac.uk/download/10672/50/English%20Government%20Office%20Network%20Regions%20(GOR).zip"
zip_file = sprintf("%s/shpfile.zip", tmp_dir)
download.file(url_data, zip_file)
unzip(zip_file, exdir = tmp_dir)
library(maptools)
#Load in the data file (could this be done from the downloaded zip file directly?
gor=readShapeSpatial(sprintf('%s/Regions.shp', tmp_dir))
#I can plot the shapefile okay...
plot(gor)
#and I can use these commands to get a feel for the data...
summary(gor)
attributes(gor@data)
gor@data$NAME
#[1] North East North West
#[3] Greater London Authority West Midlands
#[5] Yorkshire …Run Code Online (Sandbox Code Playgroud) 我找到了两种在R中打开shapefile的基本方法 - 使用rgdal和maptools:
# 1
require(maptools)
shape_maptools <- readShapeLines("file.shp")
# 2
require(rgdal)
shape_rgdal <- readOGR(".", "file")
Run Code Online (Sandbox Code Playgroud)
两种情况下的数据结构看起来完全相同(类SpatialLinesDataFrame,包sp).但是,在rgdal正确读取投影时,maptools不会(您可能需要手动分配CRS):
> proj4string(shape_maptools)
[1] NA
> proj4string(shape_rgdal)
[1] "+proj=utm +zone=31 +ellps=intl +units=m +no_defs"
Run Code Online (Sandbox Code Playgroud)
那么,为什么我会maptools用来打开形状文件?我可能只会错误地手动分配CRS!
rgdal是更安全的方式来打开shapefile吗?我想用顶部形状文件中的点绘制一个栅格图层。我已经检查了之前的答案,但仍然有问题。我可以毫无问题地分别绘制点形状文件和栅格图层,但不能一起绘制。
据我所知,它们应该位于相同的投影和位置。
require(maptools)
myproj <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
shape <- readShapeSpatial("directory/mypoints.shp", proj4string = CRS(myproj))
plot(r <- raster(listVI[200]))
plot(shape)
Run Code Online (Sandbox Code Playgroud) 我有一个形状文件,我想用 ggplot 将其发布在谷歌地图上,但是通过 geom_polygon(ggplot2) 发布会显示没有意义的线条
我的代码:
######## the shape file ftp://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2015/Brasil/BR/
download.file("ftp://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2015/Brasil/BR/br_municipios.zip",temp)
data <- unz(temp, "BRMUE250GC_SIR.shp")
data.shape<-st_read(data)
####### the map from ggmap
mapa_edital_guarulhos <- get_map(location="GUARULHOS-SP",zoom=11,color = "bw",
maptype = "roadmap")
mapa_edital_guarulhos_01<- ggmap(mapa_edital_guarulhos)
########## plotting with ggplot
mapa_edital_guarulhos1 <- mapa_edital_guarulhos_01 +
geom_polygon(aes(x=long,y=lat, group=group), data=shape.sp,
color='black',alpha=0)
Run Code Online (Sandbox Code Playgroud)
结果:
箭头显示的线条在我的图中没有意义,仅绘制相同间隔的形状:
plot(shape.sp,xlim=c(-47.25,-46.95),ylim=c(-23.1,-22.7))
Run Code Online (Sandbox Code Playgroud)
我的代码有什么问题吗?谢谢
我对 AWS EMR 和 apache Spark 完全陌生。我正在尝试使用 shapefile 将 GeoID 分配给住宅物业。我无法从我的 s3 存储桶中读取 shapefile。请帮助我了解发生了什么,因为我在互联网上找不到任何解释确切问题的答案。
<!-- language: python 3.4 -->
import shapefile
import pandas as pd
def read_shapefile(shp_path):
"""
Read a shapefile into a Pandas dataframe with a 'coords' column holding
the geometry information. This uses the pyshp package
"""
#read file, parse out the records and shapes
sf = shapefile.Reader(shp_path)
fields = [x[0] for x in sf.fields][1:]
records = sf.records()
shps = [s.points for s in sf.shapes()]
center = [shape(s).centroid.coords[0] …Run Code Online (Sandbox Code Playgroud) 我想绘制一个shapefile使用 geopandas 的图。我希望线条的粗细符合shapefile. 我为此使用以下命令:
shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5), linewidth=shp_sub['Case1_2'], edgecolor='0.8', vmin=0, vmax=1)
Run Code Online (Sandbox Code Playgroud)
这意味着厚度和颜色代码应该相互匹配。
我已经尝试过这个:
shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5), linewidth=1, edgecolor='0.8', vmin=0, vmax=1)
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,我没有得到一对一的。
shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5), linewidth=shp_sub['Case1_2'], edgecolor='0.8', vmin=0, vmax=1)
Run Code Online (Sandbox Code Playgroud)
我正在 R 中绘制栅格数据,当我调整到我正在处理的区域时,R 显示不想被切断的 ylim。
我试过:
# set lon lat
ylim=c(-4,2)
xlim=c(118,126)
plot(pm10_mean,xlim=xlim, ylim=ylim)
plot(shp, add=TRUE)
plot(shp2, add=TRUE)
Run Code Online (Sandbox Code Playgroud)
但我得到了这样的照片
如何删除 2 以上和 -4 以下的可用空间?我只想在xlim和中绘制区域ylim
我有一个多边形的形状文件,我想找到每个多边形的质心,但我得到的是整个形状文件的质心。
我使用以下代码行将我的 csv 文件转换为 shapefile (请参阅此问题Converting CSV file to shapefile - but Want Polygon not Points ):
df <- as.data.frame(read_csv("/Users/alan/Desktop/shapes.csv"))
df1 <- lapply(split(df, df$shape), function(x) { coords <- as.matrix(cbind(x$longitude,
x$latitude)); rbind(coords, coords[1,])})
Coord_Ref <- st_crs(3035)
plot_locations_df <- st_multipolygon(x=list(df1))
plot_locations_df <- st_sfc(plot_locations_df, crs = Coord_Ref)
plot(st_geometry(plot_locations_df))
plot(st_geometry(plot_locations_df, col = sf.colors(12, categorical=TRUE), border='grey',
axes=TRUE))
plot(st_geometry(st_centroid(plot_locations_df)), pch = 3, col = 'red', add=TRUE)
Run Code Online (Sandbox Code Playgroud)
我的数据框如下所示:
structure(list(shape = c(1.1, 1.1, 1.1, 1.1, 2.1, 2.1, 2.1, 2.1,
3.1, 3.1, 3.1, 3.1, 4.1, 4.1, 4.1, 4.1, …Run Code Online (Sandbox Code Playgroud) shapefile ×10
r ×7
gis ×2
google-maps ×2
plot ×2
r-maptools ×2
raster ×2
amazon-s3 ×1
geopandas ×1
ggmap ×1
ggplot2 ×1
mapping ×1
pyspark ×1
python ×1
python-3.x ×1
r-sf ×1
rgdal ×1
shapes ×1
tiger-lines ×1