如何将shapefile转换为纬度和经度边界?


12

我有一个国家分区的shapefile,我想为每个分区提取一个经纬度和纬度的数组..可以这样做吗?


请说明:您有shapefile还是Excel文件?
ub

1
标题并不能真正反映您的问题,请考虑对其进行编辑。
DavidF 2010年

我有一个shapefile
mossplix

Answers:


25

使用OSGEO的ogr Python模块,此示例将为您提供一个元组,其中包含为每个功能定义信封的坐标。

from osgeo import ogr

ds = ogr.Open("mn_counties.shp")
lyr = ds.GetLayerByName("mn_counties")

lyr.ResetReading()

for feat in lyr:
    # get bounding coords in minx, maxx, miny, maxy format
    env = feat.GetGeometryRef().GetEnvelope()
    # get bounding coords in minx, miny, maxx, maxy format
    bbox = [env[0], env[2], env[1], env[3]]
    print env
    print bbox
    print

2
...以及免费的地理空间python; /
DavidF

4

一种使用SAGA GIS的可能方法http://www.saga-gis.org 打开shapefile后,请运行以下3个模块:1. Modules \ Shapes \ Tools \ Get Shapes范围

  1. 线中的Modules \ Shapes \ Tools \ Points \ Points [与名称所暗示的相反,您还可以使用它从多边形中获取点]

  2. 模块\形状\工具\点\将坐标添加到点这将为您提供一个表,其中包含多边形文件的边界框的4个角的x和y坐标。


4

在arcgis中,这是python代码。结果是minx,miny,maxx,maxy,minM,maxM,minZ,maxZ的列表(

import arcpy
for feat in arcpy.SearchCursor(r"c:\data\f.gdb\counties"):
    print feat.Shape.extent

-2.66852727251546 49.4265363633626 -2.52848181818121 49.5079454546192 NaN NaN NaN NaN
-10.463336363782 51.4455454544593 -6.01305454583045 55.3799909091533 NaN NaN NaN NaN
-4.77778181827614 54.0555454544593 -4.35347272688468 54.4100000000002 NaN NaN NaN NaN

4

这是R版本,使用来自rgdal包的示例数据:

library(rgdal)
dsn <- system.file("vectors/ps_cant_31.MIF", package = "rgdal")[1]
d <- readOGR(dsn = dsn, layer="ps_cant_31")

## transform if this is not longlat
if (is.projected(d)) d <- spTransform(d, CRS("+proj=longlat +ellps=WGS84"))

for (i in 1:nrow(d)) {
  print(bbox(d[i,]))    
}

1

我使用fiona并匀称地执行此类任务:

import fiona
from shapely.geometry import shape

with fiona.open(r'd:\Projects\_00_Data\_USstates\fe_2007_us_state00.shp', 'r') as features:
    for i, feat in enumerate(features):
        geom = shape(feat['geometry'])
        name = feat['properties']['NAME00']
        print ','.join((name,) + tuple([str(i) for i in geom.bounds]))

那不提供纬度/经度。
harvpan

输出看起来像这样,它们是经/纬度坐标:-124.72583900000001,45.544321,-116.915989,49.002494 -82.626182,37.202467,-77.71951899999999,40.638801 -111.056888,40.996345999999996,-104.052287,45.005904 -67.955811,17.913769,-65。
Matej
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.