text stringlengths 0 828 |
|---|
index = rtree.index.Index() |
for i in tqdm(range(len(bounds_shapes))): |
(feature, shape) = bounds_shapes[i] |
index.insert(i, shape.bounds) |
features_keep = [] |
for feature in tqdm(obj['features']): |
if 'geometry' in feature and 'coordinates' in feature['geometry']: |
coordinates = feature['geometry']['coordinates'] |
if any([ |
shape.contains(shapely.geometry.Point(lon, lat)) |
for (lon, lat) in coordinates |
for (feature, shape) in [bounds_shapes[i] |
for i in index.nearest((lon,lat,lon,lat), 1)] |
]): |
features_keep.append(feature) |
continue |
obj['features'] = features_keep |
return obj" |
4360,"def features_node_edge_graph(obj): |
"""""" |
Transform the features into a more graph-like structure by |
appropriately splitting LineString features into two-point |
""edges"" that connect Point ""nodes"". |
"""""" |
points = {} |
features = obj['features'] |
for feature in tqdm(obj['features']): |
for (lon, lat) in geojson.utils.coords(feature): |
points.setdefault((lon, lat), 0) |
points[(lon, lat)] += 1 |
points = [p for (p, c) in points.items() if c > 1] |
features = [geojson.Point(p) for p in points] |
# For each feature, split it into ""edge"" features |
# that occur between every point. |
for f in tqdm(obj['features']): |
seqs = [] |
seq = [] |
for point in geojson.utils.coords(f): |
if len(seq) > 0: |
seq.append(point) |
if point in points: |
seq.append(point) |
if len(seq) > 1 and seq[0] in points: |
seqs.append(seq) |
seq = [point] |
for seq in seqs: |
features.append(geojson.Feature(geometry={""coordinates"":seq, ""type"":f['geometry']['type']}, properties=f['properties'], type=f['type'])) |
obj['features'] = features |
return obj" |
4361,"def get_conn(filename): |
""""""Returns new sqlite3.Connection object with _dict_factory() as row factory"""""" |
conn = sqlite3.connect(filename) |
conn.row_factory = _dict_factory |
return conn" |
4362,"def conn_is_open(conn): |
""""""Tests sqlite3 connection, returns T/F"""""" |
if conn is None: |
return False |
try: |
get_table_names(conn) |
return True |
# # Idea taken from |
# # http: // stackoverflow.com / questions / 1981392 / how - to - tell - if -python - sqlite - database - connection - or -cursor - is -closed |
# conn.execute(""select id from molecule limit 1"") |
# return True |
except sqlite3.ProgrammingError as e: |
# print(e) |
return False" |
4363,"def cursor_to_data_header(cursor): |
""""""Fetches all rows from query (""cursor"") and returns a pair (data, header) |
Returns: (data, header), where |
- data is a [num_rows]x[num_cols] sequence of sequences; |
- header is a [num_cols] list containing the field names |
"""""" |
n = 0 |
data, header = [], {} |
for row in cursor: |
if n == 0: |
header = row.keys() |
data.append(row.values()) |
return data, list(header)" |
4364,"def get_table_info(conn, tablename): |
""""""Returns TableInfo object"""""" |
r = conn.execute(""pragma table_info('{}')"".format(tablename)) |
ret = TableInfo(((row[""name""], row) for row in r)) |
return ret" |
4365,"def find(self, **kwargs): |
"""""" |
Finds row matching specific field value |
Args: |
**kwargs: (**only one argument accepted**) fielname=value, e.g., formula=""OH"" |
Returns: list element or None |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.