text stringlengths 0 828 |
|---|
4353,"def _SignedVarintEncoder(): |
""""""Return an encoder for a basic signed varint value."""""" |
local_chr = chr |
def EncodeSignedVarint(write, value): |
if value < 0: |
value += (1 << 64) |
bits = value & 0x7f |
value >>= 7 |
while value: |
write(0x80|bits) |
bits = value & 0x7f |
value >>= 7 |
return write(bits) |
return EncodeSignedVarint" |
4354,"def match(value, query): |
"""""" |
Determine whether a value satisfies a query. |
"""""" |
if type(query) in [str, int, float, type(None)]: |
return value == query |
elif type(query) == dict and len(query.keys()) == 1: |
for op in query: |
if op == ""$eq"": return value == query[op] |
elif op == ""$lt"": return value < query[op] |
elif op == ""$lte"": return value <= query[op] |
elif op == ""$gt"": return value > query[op] |
elif op == ""$gte"": return value >= query[op] |
elif op == ""$ne"": return value != query[op] |
elif op == ""$in"": return value in query[op] |
elif op == ""$nin"": return value not in query[op] |
else: GeoQLError(""Not a valid query operator: "" + op) |
else: |
raise GeoQLError(""Not a valid query: "" + str(query))" |
4355,"def features_properties_null_remove(obj): |
"""""" |
Remove any properties of features in the collection that have |
entries mapping to a null (i.e., None) value |
"""""" |
features = obj['features'] |
for i in tqdm(range(len(features))): |
if 'properties' in features[i]: |
properties = features[i]['properties'] |
features[i]['properties'] = {p:properties[p] for p in properties if properties[p] is not None} |
return obj" |
4356,"def features_tags_parse_str_to_dict(obj): |
"""""" |
Parse tag strings of all features in the collection into a Python |
dictionary, if possible. |
"""""" |
features = obj['features'] |
for i in tqdm(range(len(features))): |
tags = features[i]['properties'].get('tags') |
if tags is not None: |
try: |
tags = json.loads(""{"" + tags.replace(""=>"", "":"") + ""}"") |
except: |
try: |
tags = eval(""{"" + tags.replace(""=>"", "":"") + ""}"") |
except: |
tags = None |
if type(tags) == dict: |
features[i]['properties']['tags'] = {k:tags[k] for k in tags} |
elif tags is None and 'tags' in features[i]['properties']: |
del features[i]['properties']['tags'] |
return obj" |
4357,"def features_keep_by_property(obj, query): |
"""""" |
Filter all features in a collection by retaining only those that |
satisfy the provided query. |
"""""" |
features_keep = [] |
for feature in tqdm(obj['features']): |
if all([match(feature['properties'].get(prop), qry) for (prop, qry) in query.items()]): |
features_keep.append(feature) |
obj['features'] = features_keep |
return obj" |
4358,"def features_keep_within_radius(obj, center, radius, units): |
"""""" |
Filter all features in a collection by retaining only those that |
fall within the specified radius. |
"""""" |
features_keep = [] |
for feature in tqdm(obj['features']): |
if all([getattr(geopy.distance.vincenty((lat,lon), center), units) < radius for (lon,lat) in geojson.utils.coords(feature)]): |
features_keep.append(feature) |
obj['features'] = features_keep |
return obj" |
4359,"def features_keep_using_features(obj, bounds): |
"""""" |
Filter all features in a collection by retaining only those that |
fall within the features in the second collection. |
"""""" |
# Build an R-tree index of bound features and their shapes. |
bounds_shapes = [ |
(feature, shapely.geometry.shape(feature['geometry'])) |
for feature in tqdm(bounds['features']) |
if feature['geometry'] is not None |
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.