Query your own map layers#
Use read_file to inspect a map layer immediately and check that its attributes, geometry and coordinate system match the source. The reader is chosen from the extension or dataset directory. Supply a format hint if the filename is unconventional.
FileGDB, GeoPackage and OSM PBF require a logical layer, while KML permits one. For CSV, declare how to read the geometry even if a column visibly contains WKT. For the exact format, layer and CRS options, see File formats, layers and coordinate metadata.
Inspect a CSV layer#
From cugeo-geometry/, read the checked fixture and inspect its columns, geometry and occurrence indexes.
import cugeo.geometry as cg
s = cg.Session()
f = cg.read_file(
'tests/fixtures/eager-files/points.csv',
format='csv',
options={'delimiter': ';', 'geometry': {'type': 'wkt', 'column': 'shape'}},
columns=['name', 'payload'],
session=s,
)
print(list(f.columns), f.active_geometry_name, f.crs)
print(f['payload'].to_arrow().to_pylist())
print(f.index.to_pandas().tolist())
With the GeoPandas export extra installed, inspect the geometry values too.
print(f.geometry.to_geopandas().to_wkt().tolist())
These conversions bring the inspected values to the host. Check for name and payload alongside the active geometry column, an unknown CRS, payloads [7, 3, 7, 7] and occurrence indexes [0, 1, 2, 3]. Two rows contain the point (5, 5), one has empty point geometry and one has missing geometry. The separate occurrence indexes let you account for all four records even when values repeat.
Use your own layer#
Use your file’s path and options. Compare a known attribute and its geometry with the source, check the CRS declaration, and explicitly resolve an ambiguous active geometry. Keep the session open for subsequent computation.
If you need a SQL input, table_from_file snapshots the options without I/O. For a deferred frame, scan_file requires a logical geometry selector and reads on collection. If you already have a SQL file, continue with the relation-to-file mapping in Run saved spatial SQL from the shell.