Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#data_fl = FeatureLayer(url=indicator_url, gis=self.gis_conn)
# Enumerate Used to Leverage the Merge Method on the Data Frame.
# Set the First and Merge the Remainder to the First.
for idx, row in enumerate(self.grid_sdf.iterrows()):
# Negative Buffer Used to Avoid Selecting More Than 1 Cell
sp_filter = filters.intersects(
Geometry(row[1].SHAPE).buffer(-.1),
self.grid_wkid
)
if not indicator_url:
df_current = SpatialDataFrame(
columns=field_schema.get(indicator),
geometry=[Geometry(json.loads(row[1].SHAPE.JSON))]
)
created = True
else:
# Negative Buffer to Select a Single Grid Cell
sp_filter = filters.intersects(
Geometry(row[1].SHAPE).buffer(-.1),
self.grid_wkid
)
df_current = data_fl.query(geometry_filter=sp_filter,
return_all_records=self.return_all_records).df
# Set The First Instance
if idx == 0:
# Check If Cell Found in Target Indicator Layer
m1, n1, m2, n2 = box
x, y = p
if x >= m1 and x <= m2 and y >= n1 and y <= n2:
return True
return False
return (point_in((x1, y1), b)) or (point_in((x2, y1), b)) or (point_in((x2, y2), b)) or (point_in((x1, y2), b))
# iterate through image tiles on naip_image_layer starting from bottom row
for y_idx in range(y_num_tile):
for x_idx in range(x_num_tile):
image_name = str(y_idx*x_num_tile + x_idx)
x_start = min_x + x_idx * tile_size
y_start = min_y + y_idx * tile_size
# export annotations for buildings in the image
tile_image_geometry = Geometry({
"rings" : [[[x_start,y_start],[x_start+tile_size,y_start],[x_start+tile_size,y_start+tile_size],[x_start,y_start+tile_size]]],
"spatialReference" : {"wkid" : crs_id}
})
annotations = []
for idx, bbox in enumerate(building_data.geometry):
# bbox is polygon
bbox_extent = bbox.extent
tile_extent = tile_image_geometry.extent
try:
# if bbox overlaps with tile image extent, record the building bbox
if overlap(bbox_extent, tile_extent):
# bbox contains normalized [xywh]
x1_r, y1_r, x2_r, y2_r = bbox_extent
# clipping
x1 = max(x_start, x1_r)
y1 = max(y_start, y1_r)
def validate_img_gis(geo_gis, img_url):
try:
img_lyr = ImageryLayer(img_url, gis=geo_gis)
img_lyr.get_samples(Geometry({"x":-122.435,"y":37.785}), geometry_type='esriGeometryPoint')
print('Thematic Service GIS: {}'.format(geo_gis))
except RuntimeError:
raise Exception('{} Does Not Support getSamples on Service: {}'.format(geo_gis, img_url))
look_back_days = config.look_back_days
dates = csl.get_dates_in_range(look_back_days)
where_clause = csl.form_query_string(dates)
grid_fl = FeatureLayer(url=config.grid_url)
grid_sdf = grid_fl.query(return_all_records=return_all_records, where=where_clause).df
geometry = grid_sdf.geometry
sr = {'wkid':4326}
sp_rel = "esriSpatialRelIntersects"
for idx, row in enumerate(grid_sdf.iterrows()):
geom = row[1].SHAPE
new_geom = Geometry({
"rings" : [[[geom.extent.upperRight.X-.1, geom.extent.lowerLeft.Y+.1], [geom.extent.lowerLeft.X+.1, geom.extent.lowerLeft.Y+.1], [geom.extent.lowerLeft.X+.1, geom.extent.upperRight.Y-.1], [geom.extent.upperRight.X-.1, geom.extent.upperRight.Y-.1], [geom.extent.upperRight.X-.1, geom.extent.lowerLeft.Y+.1]]],
"spatialReference" : {"wkid" : 4326}
})
grid_filter = filters._filter(new_geom, sr, sp_rel)
sp_filter = filters._filter(geom, sr, sp_rel)
data_fl = FeatureLayer(url=config.features_url)
#out_fields=in_fields,
data_sdf = data_fl.query(geometry_filter=sp_filter,return_geometry=True,
return_all_records=return_all_records).df
print('Processing Completeness')
#bounding_box = '(37.708132, -122.513617, 37.832132, -122.349607)'
bounding_box = '(' + \
str(geom.extent.lowerLeft.Y) + ',' + \
created = False
out_sdf = None
# Indicator Feature Layer
indicator_url = self.__getattribute__(indicator + '_url')
print(indicator_url)
#data_fl = FeatureLayer(url=indicator_url, gis=self.gis_conn)
# Enumerate Used to Leverage the Merge Method on the Data Frame.
# Set the First and Merge the Remainder to the First.
for idx, row in enumerate(self.grid_sdf.iterrows()):
# Negative Buffer Used to Avoid Selecting More Than 1 Cell
sp_filter = filters.intersects(
Geometry(row[1].SHAPE).buffer(-.1),
self.grid_wkid
)
if not indicator_url:
df_current = SpatialDataFrame(
columns=field_schema.get(indicator),
geometry=[Geometry(json.loads(row[1].SHAPE.JSON))]
)
created = True
else:
# Negative Buffer to Select a Single Grid Cell
sp_filter = filters.intersects(
Geometry(row[1].SHAPE).buffer(-.1),
self.grid_wkid
)
# # Push Significant Values Into List for Averaging
# if enriched_pop or sample_total < 100:
# pass
# else:
# diff = abs(enriched_pop - sample_total)
# if diff > 100:
# pop_diff.append(diff)
#
# tot_pop = enriched_pop if enriched_pop > 0 else sample_total
# tot_pop = tot_pop if tot_pop > 0 else -1
##-----------------------------------------------------------------------------
them_lyr = FeatureLayer(url=them_url, gis=them_gis)
geom = Geometry(row[1].SHAPE).buffer(-.01)
sp_filter = filters.intersects(geom, 4326)
them_sdf = them_lyr.query(geometry_filter=sp_filter, return_all_records=True).df
#print(them_sdf)
if len(df_current) > 0:
count = len(df_current)
max_val = df_current[f_thm_acc].max()
max_scale = 100 * (len(df_current[df_current[f_thm_acc] == max_val])/count)
min_val = df_current[f_thm_acc].min()
min_scale = 100 * (len(df_current[df_current[f_thm_acc] == min_val])/count)
vc = df_current[f_thm_acc].value_counts()
common = df_current[f_thm_acc].mode() # Used in MSP
mean = df_current[f_thm_acc].mean()