Simple Spatial Routines




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

Locate Excluded Targets

{ target_geotable : Targets ? Locate targets that you want to connect to a source }

{ source_geotable : Sources ? Locate sources }

{ source_range_in_meters : Source Range in Meters ? Specify the maximum distance at which a source can service a target }

In [6]:
# CrossCompute
target_geotable_path = 'random-polygons.csv'
source_geotable_path = 'random-lines.csv'
source_range_in_meters = 35000
target_folder = '/tmp'
In [9]:
import geotable
utm_proj4 = geotable.load_utm_proj4(target_geotable_path)
target_geotable = geotable.load(target_geotable_path, target_proj4=utm_proj4)
source_geotable = geotable.load(source_geotable_path, target_proj4=utm_proj4)
print('target_count = %s' % len(target_geotable))
target_count = 100
In [10]:
from shapely.geometry import GeometryCollection
source_collection = GeometryCollection(source_geotable.geometries)
In [12]:
excluded_indices = []
for index, row in target_geotable.iterrows():
    g = row['geometry_object']
    if source_collection.distance(g) <= source_range_in_meters:
        continue
    excluded_indices.append(index)
In [13]:
from os.path import join
target_path = join(target_folder, 'excluded-target.kmz')
t = target_geotable
t = t.iloc[excluded_indices]
t.save_kmz(target_path)
print('excluded_target_count = %s' % len(t))
print('excluded_target_geotable_path = %s' % target_path)
excluded_target_count = 94
excluded_target_geotable_path = /tmp/excluded-target.kmz

Excluded Targets

{ target_count : Target Count ? Number of targets }

{ excluded_target_count : Excluded Target Count ? Number of targets that are too far from a source }

{ excluded_target_geotable : Excluded Targets ? Targets that are too far from a source }