{ feature_geotable : Features ? Select from these features }
{ region_geotable : Region of Interest ? Select features that intersect this region }
# CrossCompute
feature_geotable_path = 'random-polygons.csv'
region_geotable_path = 'selected-region.csv'
target_folder = '/tmp'
import geotable
proj4 = geotable.LONGITUDE_LATITUDE_PROJ4
feature_geotable = geotable.load(feature_geotable_path, target_proj4=proj4)
feature_geometries = feature_geotable.geometries
print('feature_count = %s' % len(feature_geotable))
from shapely.ops import unary_union
region_geotable = geotable.load(region_geotable_path, target_proj4=proj4)
region_geometry = unary_union(region_geotable.geometries)
intersected_flags = []
contained_flags = []
for g in feature_geometries:
intersected_flags.append(region_geometry.intersects(g))
contained_flags.append(region_geometry.contains(g))
feature_geotable['is_intersected'] = intersected_flags
feature_geotable['is_contained'] = contained_flags
from os.path import join
target_path = join(target_folder, 'selected-features.csv')
t = feature_geotable
t = t[t['is_intersected']]
t.save_csv(target_path, target_proj4=proj4)
print('selected_feature_count = %s' % len(t))
print('selected_feature_geotable_path = %s' % target_path)
{ feature_count : Feature Count ? Number of features in original dataset }
{ selected_feature_count : Selected Feature Count ? Number of features that intersect region of interest }
{ selected_feature_geotable : Selected Features ? Features intersecting region of interest }