如何检查 shapefile 列表中的点是否落在里面并且与给定的 FIELD 相同?

How to check in a list of shapefiles whether a point falls inside AND it is the same of a given FIELD?

我正在绘制地址点并检查它们是否在大型 shapefile 中。 但是,现在我还想检查它们是否属于 URBAN 类型。此信息以功能列表的形式出现,其中一列是 TYPE。我要的点是不是市区我pass(urban=True)

我的收币点代码:

def get_random_point_in_polygon(region, urban=None):
    while True:
        address = ogr.Geometry(ogr.wkbPoint)    
        address.AddPoint(random.uniform(region.get_region().geometry().GetEnvelope()[0],
                                    region.get_region().geometry().GetEnvelope()[1]),
                     random.uniform(region.get_region().geometry().GetEnvelope()[2],
                                    region.get_region().geometry().GetEnvelope()[3]))
        if region.get_region().geometry().Contains(address) and XXXXXXXXXX:
            return address

区域是一个大的 shapefile 现在我还有一个包含其他 52 个特征的列表,这些特征都在区域内。 他们有一个 FIELD,其中包含 URBAN 或 RURAL 信息。

我想使用如下代码来完成我的 XXXXXX:'if address is inside any features in the list that FIELD = URBAN'

有什么想法吗? 类似于:

any(x in a for x in b)

但对于 shapefile...

我想我找到了解决办法,虽然比较麻烦。 ShapesInput.urban 是功能列表

但是,请注意,此代码非常昂贵。而且考虑到城市比农村小很多,确实需要很长时间。

好吧,它有效...

def get_random_point_in_polygon(region, urban=True):
    while True:
        address = ogr.Geometry(ogr.wkbPoint)
        address.AddPoint(random.uniform(region.get_region().geometry().GetEnvelope()[0],
                                    region.get_region().geometry().GetEnvelope()[1]),
                     random.uniform(region.get_region().geometry().GetEnvelope()[2],
                                    region.get_region().geometry().GetEnvelope()[3]))
        if region.get_region().geometry().Contains(address):
            if urban is True:
                for item in ShapesInput.urban:
                    if item.geometry().Contains(address):
                        return address
            else:
                return address