我有一个地理标记列表(lat,long)和一个包含不同图层的shapefile。我希望能够识别哪个层属于每个coord。
但是shapefile(.shp)有一些poligons,其中纬度和经度以奇数范围内的数字表示,例如120724.86008864和484497.34058312
我知道prj文件包含有关如何进行此转换的信息,但我似乎没有得到如何。就是这样:
PROJCS [ “RD_New”,GEOGCS [ “GCS_Amersfoort”,DATUM [ “D_Amersfoort”,SPHEROID [ “Bessel_1841”,6377397.155,299.1528128],PRIMEM [ “格林威治”,0],单位[ “度”,0.0174532925199432955] ],投影[ “Double_Stereographic”],PARAMETER [ “False_Easting”,155000],PARAMETER [ “False_Northing”,463000],PARAMETER [ “Central_Meridian”,5.38763888888889],PARAMETER [ “Scale_Factor”,0.9999079],PARAMETER [ “Latitude_Of_Origin” ,52.15616055555555],单位[ “表”,1]]
具体问题是如何将常规lat / long点转换为shapefile的那些。
在Python中工作感谢任何帮助。
答案 0 :(得分:0)
import re
regex = "\d{1,3}\.\d+"
s ="""PROJCS["RD_New",GEOGCS["GCS_Amersfoort",DATUM["D_Amersfoort",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199432955]],PROJECTION["Double_Stereographic"],PARAMETER["False_Easting",155000],PARAMETER["False_Northing",463000],PARAMETER["Central_Meridian",5.38763888888889],PARAMETER["Scale_Factor",0.9999079],PARAMETER["Latitude_Of_Origin",52.15616055555555],UNIT["Meter",1]] """
m = re.search(regex, s)
if m:
print m.groups()
答案 1 :(得分:0)
# define input
shape_file = "file.shp"
o_lat = 52.3605883
o_lon = 4.8593157
# geospatial bureocracy
driver = ogr.GetDriverByName('ESRI Shapefile')
shape = driver.Open(shape_file)
layer = shape.GetLayer()
geo_ref = layer.GetSpatialRef()
point_ref = ogr.osr.SpatialReference()
point_ref.ImportFromEPSG(4326)
ctran = ogr.osr.CoordinateTransformation(point_ref, geo_ref)
# critical part: transform longitude/latitude to the shapefile's projection
[t_lon, t_lat, z] = ctran.TransformPoint(o_lon, o_lat)
print('original coords', o_lon, o_lat)
print('transformed coords', t_lon, t_lat)
# create the needle
point = ogr.Geometry(ogr.wkbPoint)
point.SetPoint_2D(0, t_lon, t_lat)
layer.SetSpatialFilter(point)
# look it up
for feature in layer:
polygon = feature.GetGeometryRef()
if polygon.Contains(point):
print('Found it', feature.ExportToJson()