标签: shapefile

使用Python将自定义功能属性添加到ESRI Shapefile

我正在寻找一种方法来获取一个功能集为200个国家的现有ESRI Shapefile.每个国家/地区要素都具有"NAME"属性.我的目标是创建一个Python脚本,添加一个任意(现在)的附加属性,比如"POPULATION".

当然我安装了OSGeo和GeoDjango模块.我到目前为止:

from osgeo import ogr

infile = ogr.Open('sample.shp', 1) #'sample.shp' is a pre-existing ESRI shapefile described above
inlyr = infile.GetLayerByIndex(0)
Run Code Online (Sandbox Code Playgroud)

我错过了一个OGR函数,它允许我将Feature属性字段插入现有的Shapefile中吗?

esri shapefile osgeo geodjango ogr

6
推荐指数
1
解决办法
5594
查看次数

将R图中的多边形导出为shapefile

我一直在尝试将绘图的内容(线/多边形)导出为我可以在ArcMap中打开的图层/ shapefile.这些是我一直使用的一些库,

library(shapefiles)
library(PBSmapping)
library(adehabitatHR)
library(maptools)
library(maps)
library(rgdal)
library(igraph)
Run Code Online (Sandbox Code Playgroud)

我的纬度/经度数据如下所示:

tagdata<-read.table(text="meanlat  meanlong
-18.63327 147.0248
-18.6368  147.0238
-18.62068 147.294
-18.62953 147.2942
-18.62953 147.2942
-18.62091 147.2938
-18.62953 147.2942
-18.62466 147.2926
-18.73393 147.2816
-18.73393 147.2816
-18.75383 147.2541
-18.75383 147.2541
-18.75383 147.2541
-18.75383 147.2541
-18.6368  147.0238
-18.63063 147.0256
-18.63063 147.0256
-18.68133 147.1164
-18.6368  147.0238
-18.63063 147.0256
-18.63063 147.0256
-18.75383 147.2541
-18.61273 147.0682
-18.69655 147.09
-18.6368  147.0238
-18.63063 147.0256
-18.63063 147.0256
-18.63217 147.0251
-18.75383 147.2541
-18.75383 147.2541
-18.75383 147.2541
-18.63063 147.0256
-18.68133 147.1164
-18.68133 147.1164 …
Run Code Online (Sandbox Code Playgroud)

export r polygon shapefile

6
推荐指数
1
解决办法
1万
查看次数

如何将SVG转换为SHP(形状文件)格式?

我试图将SVG文件转换为SHP(形状文件格式),然后将其导入GeoServer.

有没有可用的转换器或者是否有任何中介格式,我可以将其转换为最终以SHP格式获取?

我已经有了印度地图的形状文件.现在,近年来增加了一些奇怪的60个区.新区与旧区分开.因此,该国的总面积没有变化,但是分歧了.

我的想法是,如果我可以将SVG格式的新区域的新图层合并到原始SHP文件数据并根据SHP文件获取最终坐标,则可以对问题进行排序.

如果有人这样做并且可以提供帮助,那就太棒了!谢谢!!

svg dictionary converter shapefile geoserver

6
推荐指数
1
解决办法
8685
查看次数

功能强化ggplot2时出错

我正在尝试使用包ggplot2中的fortify函数将空间对象转换为data.frame.但是我收到了一个错误.例如,遵循Hadley Wickhan的绘制多边形shapefile示例中使用的完全相同的代码,我键入以下命令行:

 require("rgdal") 
 require("maptools")
 require("ggplot2")
 require("plyr")
 utah = readOGR(dsn="/path/to/shapefile", layer="eco_l3_ut")
   OGR data source with driver: ESRI Shapefile 
   Source: ".", layer: "eco_l3_ut"
   with 10 features and 7 fields
   Feature type: wkbPolygon with 2 dimensions
 utah@data$id = rownames(utah@data)
Run Code Online (Sandbox Code Playgroud)

一切似乎都运作正常:

 > str(utah)
      ..@ data       :'data.frame': 10 obs. of  8 variables:
      .. ..$ AREA      : num [1:10] 1.42e+11 1.33e+11 3.10e+11 4.47e+10 1.26e+11 ...
      .. ..$ PERIMETER : num [1:10] 4211300 3689180 4412500 2722190 3388270 ...
      .. ..$ USECO_    : int [1:10] 164 …
Run Code Online (Sandbox Code Playgroud)

r shapefile ggplot2 fortify

6
推荐指数
1
解决办法
3400
查看次数

如何使用空间掩码限制栅格处理范围?

我试图限制MATLAB中的光栅处理以仅包括shapefile边界内的区域,类似于ArcGIS Spatial Analyst函数使用蒙版的方式.以下是我正在使用的一些(可重现的)样本数据:

这是我用来计算NDVI的MATLAB脚本:

file = 'C:\path\to\doi1m2011_41111h4nw_usda.tif';
[I R] = geotiffread(file);
outputdir = 'C:\output\'

% Calculate NDVI
NIR = im2single(I(:,:,4));
red = im2single(I(:,:,1));

ndvi = (NIR - red) ./ (NIR + red);
double(ndvi);
imshow(ndvi,'DisplayRange',[-1 1]);

% Stretch to 0 - 255 and convert to 8-bit unsigned integer
ndvi = floor((ndvi + 1) * 128); % [-1 1] -> [0 256]
ndvi(ndvi < 0) = 0;             % not really necessary, just …
Run Code Online (Sandbox Code Playgroud)

matlab image image-processing shapefile arcpy

6
推荐指数
1
解决办法
2751
查看次数

使用R将坐标表转换为形状文件

我在UTM区域48中有一个点坐标数据集.

  x           y       
615028.3  2261614    
615016.3  2261635    
614994.4  2261652    
Run Code Online (Sandbox Code Playgroud)

CSV文件在这里.

我想加载CSV并使用R创建shapefile.我的代码是:

library(maptools)
library(rgdal)
library(sp)

    UTMcoor=read.csv(file="https://dl.dropboxusercontent.com/u/549234/s1.csv")
    coordinates(UTMcoor)=~X+Y
    proj4string(UTMcoor)=CRS("++proj=utm +zone=48") # set it to UTM
    LLcoor<-spTransform(UTMcoor,CRS("+proj=longlat")) #set it to Lat Long
    plot(LLcoor)
    points(LLcoor$X,LLcoor$Y,pch=19,col="blue",cex=0.8) #to test if coordinate can be plot as point map
    writeOGR(UTMcoor, dsn="c:/todel" ,layer="tsb",driver="ESRI Shapefile")
    writeSpatialShape("LLcoor","test")
Run Code Online (Sandbox Code Playgroud)

在最后一个命令(writeSpatialShape)中,R给出以下错误:

Error in writeSpatialShape("LL2", "test") : 
  x is acharacterobject, not a compatible Spatial*DataFrame
Run Code Online (Sandbox Code Playgroud)

当我从控制台读取LLcoor时,它似乎已经是一个Spatial DataFrame.使用writeOGR(RGdal包)编写形状文件也会产生类似的错误.任何提示都非常感谢.

r shapefile

6
推荐指数
1
解决办法
9867
查看次数

如何将美国人口普查局的国家级形状文件组合成一个全国性的形状

人口普查局没有提供全国范围的公共使用微观数据区域(美国社区调查中可用的最小地理位置).我尝试将它们全部用几种不同的方法组合在一起,但即使是那些一旦它击中加利福尼亚就会使标识符失效的方法.我是在做傻事还是这需要一个困难的解决方法?这里是重现事情的代码.

library(taRifx.geo)
library(maptools)

td <- tempdir() ; tf <- tempfile()
setInternet2( TRUE )
download.file( "ftp://ftp2.census.gov/geo/tiger/TIGER2014/PUMA/" , tf )

al <- readLines( tf )
tl <- al[ grep( "geo/tiger/TIGER2014/PUMA/tl_2014_" , al ) ]
fp <- gsub( "(.*)geo/tiger/TIGER2014/PUMA/tl_2014_([0-9]*)_puma10\\.zip(.*)" , "\\2" , tl )

# get rid of alaska
fp <- fp[ fp != '02' ]

af <- paste0( "ftp://ftp2.census.gov/geo/tiger/TIGER2014/PUMA/tl_2014_" , fp , "_puma10.zip" )

d <- NULL
for ( i in af ){
    try( file.remove( z ) , silent = TRUE ) …
Run Code Online (Sandbox Code Playgroud)

gis r map shapefile census

6
推荐指数
2
解决办法
867
查看次数

读取c#中的shapefile坐标

我想使用shapefile的内容在纬度/经度上绘制"XAML Map Control"上的折线.

我有2种shapefile:

  • 一个是.dbf,.prj,qpj,.shx和明显的.shp文件.
  • 一个只有.shp文件

使用各种库(Net Topology Suite,现在是DotSpatial)读取这两种类型的文件,我获得了一个坐标列表(DotSpatial.Topology.Coordinate),如:

X   456874.625438354
Y   5145767.7929015327  
Run Code Online (Sandbox Code Playgroud)
  • 我如何将其转换为纬度/经度格式?
  • 目前的格式是什么?
  • .shp文件附带的文件是否有用?

c# wpf shapefile topography dotspatial

6
推荐指数
1
解决办法
6895
查看次数

Python:为道路shapefile分配点

我有一些来自gps数据(Lat,Lon)和shapefile我正在考虑的区域的相对数据点.所以:

import pandas as pd
import shapefile
sf = shapefile.Reader('roadshape')
df = pd.read_csv('gpsdata.csv')
Run Code Online (Sandbox Code Playgroud)

现在df包含我正在分析的数据是这样的:

 ID          x          y
3447    11.400427   48.816806
3448    11.400759   48.816772
3449    11.401424   48.816684
3450    11.401758   48.816631
3451    11.402090   48.816566
3452    11.402422   48.816490
Run Code Online (Sandbox Code Playgroud)

我想分配给每个相应的shapefile细分市场.我正在尝试执行以下操作.我正在考虑边界框,我想尝试查看数据指向数据栏的边界框.

dfs = pd.DataFrame()
shapes = sf.shapes()
X =list()
Y=list()
for i in range(0,len(shapes)):
      X.append([shapes[i].bbox[0],shapes[i].bbox[2]])
      Y.append([shapes[i].bbox[1],shapes[i].bbox[3]])
dfs['X'] = X
dfs['Y'] = Y
Run Code Online (Sandbox Code Playgroud)

现在我该如何查看我的积分是哪个bbox?哪里dfs是这样的

dfs = 
                 X                             Y
0   [10.9467244189, 10.9704393002]  [48.2671975178, 48.2697440003]
1   [11.5138847999, 11.5143541004]  [48.6497096997, 48.6515363002] …
Run Code Online (Sandbox Code Playgroud)

python geolocation shapefile

6
推荐指数
1
解决办法
281
查看次数

从铁路网络shapefile提取车站之间的路线

问题:我想从shapefile中提取两个站点之间沿铁路网络的路线,并且仅绘制此特定路线,而不是整个网络。

这是我到目前为止的内容:

我在英国的整个铁路网络中都有一个shapefile,将其绘制如下:

library(maptools)
rail <- readShapeSpatial("railnetworkLine.shp")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我也有一个包含Eastings和Northings的电台列表,例如:

 1) ABDARE 300400 202800
 2) DEIGHTN 416490  419140
Run Code Online (Sandbox Code Playgroud)

我可以将它们添加到地图中,如下所示:

plot(rail)
plot(spdf.station, add=TRUE, col="red", pch=20)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

因此,我不知道如何提取它们之间的路线并绘制该路线-信息显然在shapefile中,并且我具有测站的坐标,但我不知道如何提取它。

我设法用以下代码计算了它们之间的距离:

SpacingInMetres <- 10000
require(secrlinear)
network <- read.linearmask(data=rail, spacing=SpacingInMetres)
distance <- (networkdistance (stations[1,], stations[2,], network))/1000

# Confirm distance:
distance
>311.7893
Run Code Online (Sandbox Code Playgroud)

而且我发现您可以使用Google Maps获取沿道路的路线ggmaps(请参阅此处)。但是,如果将shapefile作为网络输入而不是Google Maps,该怎么办?

我认为也许'shp2graph'+'igraph'软件包很有用,但我无法弄清楚。有什么想法吗?

r geospatial shapefile igraph

6
推荐指数
1
解决办法
364
查看次数