我试图通过缓冲点(SEPTA地铁站[下方])和计算“事件数”进行相当简单的分析。 (也指出)位于缓冲区内。那就是它。
我已经在网上看了一些,但我找不到具体的内容。也许这很容易,没人需要问。我真的可以使用一些帮助。
我能够修复代码并为点创建缓冲区,但我似乎无法计算缓冲区内的点数。此外,'事件'我正在使用的点集,所以我用“农民市场”转换它。以下是我到目前为止所做的事情。再一次,我只需要计算点数。
from osgeo import ogr
septaclip = ogr.Open(r'/home/user/Downloads/SEPTAclip.shp')
septalyr = septaclip.GetLayer(0)
citylimits = ogr.Open(r'/home/user/Downloads/City_Limits.shp')
citylyr = citylimits.GetLayer(0)
crimestat = ogr.Open(r'/home/user/Downloads/Farmers_Markets.shp')
crimelyr = crimestat.GetLayer(0)
memory_driver = ogr.GetDriverByName('Memory')
memory_ds = memory_driver.CreateDataSource('Temp')
buff_lyr = memory_ds.CreateLayer('Buffer')
buff_feat = ogr.Feature(buff_lyr.GetLayerDefn())
multipoly = ogr.Geometry(ogr.wkbMultiPolygon)
for septafeat in septalyr:
buff_geo = septafeat.geometry().Buffer(3000)
multipoly.AddGeometry(buff_geo)
#multipoly = (multipoly.UnionCascaded())
for crimefeat in crimelyr:
buffcrime = crimefeat.geometry().Intersection(multipoly)
答案 0 :(得分:1)
尝试这个来计算交叉点后的点数:
count = 0
for crimefeat in crimelyr:
if not crimefeat.geometry().Intersection(multipoly).IsEmpty():
count += 1
或使用OGR的功能:
crime_multipoint = ogr.Geometry(ogr.wkbMultiPoint)
for crimefeat in crimelyr:
crime_multipoint.AddGeometry(crimefeat.geometry())
crime_multipoint.Intersection(multipoly).GetGeometryCount()