Simple Spatial Routines




Pay Notebook Creator: Roy Hyunjin Han0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0

Filter Features using Region of Interest

{ feature_geotable : Features ? Select from these features }

{ region_geotable : Region of Interest ? Select features that intersect this region }

In [1]:
# CrossCompute
feature_geotable_path = 'random-polygons.csv'
region_geotable_path = 'selected-region.csv'
target_folder = '/tmp'
In [2]:
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))
feature_count = 100
In [3]:
from shapely.ops import unary_union
region_geotable = geotable.load(region_geotable_path, target_proj4=proj4)
region_geometry = unary_union(region_geotable.geometries)
In [4]:
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
In [5]:
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)
selected_feature_count = 100
selected_feature_geotable_path = /tmp/selected-features.csv

Selected Features

{ 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 }