Geoparquet loader
In [1]:
Copied!
import geopandas as gpd
from shapely.geometry import box
from srai.loaders import GeoparquetLoader
from srai.constants import WGS84_CRS
import geopandas as gpd
from shapely.geometry import box
from srai.loaders import GeoparquetLoader
from srai.constants import WGS84_CRS
Basic usage¶
In [2]:
Copied!
gpql = GeoparquetLoader()
gpql = GeoparquetLoader()
In [3]:
Copied!
base_gdf = gpql.load(file_path="example_files/example.parquet")
base_gdf
base_gdf = gpql.load(file_path="example_files/example.parquet")
base_gdf
Out[3]:
pop_est | continent | name | iso_a3 | gdp_md_est | geometry | |
---|---|---|---|---|---|---|
0 | 920938 | Oceania | Fiji | FJI | 8374.0 | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... |
1 | 53950935 | Africa | Tanzania | TZA | 150600.0 | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... |
2 | 603253 | Africa | W. Sahara | ESH | 906.5 | POLYGON ((-8.66559 27.65643, -8.66512 27.58948... |
3 | 35623680 | North America | Canada | CAN | 1674000.0 | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... |
4 | 326625791 | North America | United States of America | USA | 18560000.0 | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... |
In [4]:
Copied!
base_gdf.explore()
base_gdf.explore()
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [5]:
Copied!
indexed_gdf = gpql.load(file_path="example_files/example.parquet", index_column="name")
indexed_gdf
indexed_gdf = gpql.load(file_path="example_files/example.parquet", index_column="name")
indexed_gdf
Out[5]:
pop_est | continent | iso_a3 | gdp_md_est | geometry | |
---|---|---|---|---|---|
name | |||||
Fiji | 920938 | Oceania | FJI | 8374.0 | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... |
Tanzania | 53950935 | Africa | TZA | 150600.0 | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... |
W. Sahara | 603253 | Africa | ESH | 906.5 | POLYGON ((-8.66559 27.65643, -8.66512 27.58948... |
Canada | 35623680 | North America | CAN | 1674000.0 | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... |
United States of America | 326625791 | North America | USA | 18560000.0 | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... |
In [6]:
Copied!
limited_gdf = gpql.load(
file_path="example_files/example.parquet", columns=["continent", "name", "pop_est"]
)
limited_gdf
limited_gdf = gpql.load(
file_path="example_files/example.parquet", columns=["continent", "name", "pop_est"]
)
limited_gdf
Out[6]:
continent | name | pop_est | geometry | |
---|---|---|---|---|
0 | Oceania | Fiji | 920938 | MULTIPOLYGON (((180.00000 -16.06713, 180.00000... |
1 | Africa | Tanzania | 53950935 | POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... |
2 | Africa | W. Sahara | 603253 | POLYGON ((-8.66559 27.65643, -8.66512 27.58948... |
3 | North America | Canada | 35623680 | MULTIPOLYGON (((-122.84000 49.00000, -122.9742... |
4 | North America | United States of America | 326625791 | MULTIPOLYGON (((-122.84000 49.00000, -120.0000... |
In [7]:
Copied!
# Create Texas bounding box
bbox = box(minx=-106.645646, maxx=-93.508292, miny=25.837377, maxy=36.500704)
bbox_gdf = gpd.GeoDataFrame({"geometry": [bbox]}, crs=WGS84_CRS)
cut_gdf = gpql.load(file_path="example_files/example.parquet", area=bbox_gdf)
cut_gdf
# Create Texas bounding box
bbox = box(minx=-106.645646, maxx=-93.508292, miny=25.837377, maxy=36.500704)
bbox_gdf = gpd.GeoDataFrame({"geometry": [bbox]}, crs=WGS84_CRS)
cut_gdf = gpql.load(file_path="example_files/example.parquet", area=bbox_gdf)
cut_gdf
Out[7]:
pop_est | continent | name | iso_a3 | gdp_md_est | geometry | |
---|---|---|---|---|---|---|
4 | 326625791 | North America | United States of America | USA | 18560000.0 | POLYGON ((-93.84842 29.71363, -94.69000 29.480... |
In [8]:
Copied!
cut_gdf.explore()
cut_gdf.explore()
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook