Inspect GeoPackages (.gpkg)¶
A GeoPackage is a vector data format designed to store geospatial data in a single file.
Unlike Shapefiles, all geometries, attributes, and spatial reference information are stored together in one file with the extension .gpkg.
A GeoPackage can contain multiple vector layers, making it suitable for more complex datasets and workflows.
Key characteristics
- Stored as a single
.gpkgfile - Can contain multiple vector layers
- Supports different geometry types and complex attributes
- Stores coordinate reference system (CRS) information internally
When working with GeoPackages in GeoKit, a specific layer can be selected if the file contains more than one layer.
Import required packages
GeoKit is imported to provide the required functionality for working with vector data.
In [1]:
Copied!
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pathlib
import geokit.core.vector
import geokit.core.geom
from geokit.core.get_test_data import get_test_data
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pathlib
import geokit.core.vector
import geokit.core.geom
from geokit.core.get_test_data import get_test_data
In [2]:
Copied!
# Path to gpkg folder
gadm36_NLD_path = get_test_data(
file_name="gadm36_NLD.gpkg",
)
# Get the names of the vector layers in the gpkg file
list_of_vector_layer = geokit.core.vector.listLayers(gadm36_NLD_path)
print(list_of_vector_layer)
# Path to gpkg folder
gadm36_NLD_path = get_test_data(
file_name="gadm36_NLD.gpkg",
)
# Get the names of the vector layers in the gpkg file
list_of_vector_layer = geokit.core.vector.listLayers(gadm36_NLD_path)
print(list_of_vector_layer)
['gadm36_NLD_2', 'gadm36_NLD_1', 'gadm36_NLD_0']
Load Vector Layers¶
The GeoPackage file consists of multiple vector layers. You can read all of them or a specific one, as demonstrated below.
In [3]:
Copied!
# Load all vector layers from gpgk file.
netherland_vector_complete = geokit.core.vector.extractFeatures(source=gadm36_NLD_path)
# Load specific vector layer from the geopkg file
netherland_vector_0 = geokit.core.vector.extractFeatures(source=gadm36_NLD_path, layerName="gadm36_NLD_0")
netherland_vector_1 = geokit.core.vector.extractFeatures(source=gadm36_NLD_path, layerName="gadm36_NLD_1")
netherland_vector_2 = geokit.core.vector.extractFeatures(source=gadm36_NLD_path, layerName="gadm36_NLD_2")
# Load all vector layers from gpgk file.
netherland_vector_complete = geokit.core.vector.extractFeatures(source=gadm36_NLD_path)
# Load specific vector layer from the geopkg file
netherland_vector_0 = geokit.core.vector.extractFeatures(source=gadm36_NLD_path, layerName="gadm36_NLD_0")
netherland_vector_1 = geokit.core.vector.extractFeatures(source=gadm36_NLD_path, layerName="gadm36_NLD_1")
netherland_vector_2 = geokit.core.vector.extractFeatures(source=gadm36_NLD_path, layerName="gadm36_NLD_2")
In [4]:
Copied!
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(10, 8))
ax_handles = geokit.core.geom.drawGeoms(geoms=netherland_vector_complete, ax=axs[0, 0])
ax_handles = geokit.core.geom.drawGeoms(geoms=netherland_vector_0, ax=axs[0, 1])
ax_handles = geokit.core.geom.drawGeoms(geoms=netherland_vector_1, ax=axs[1, 0])
ax_handles = geokit.core.geom.drawGeoms(geoms=netherland_vector_2, ax=axs[1, 1])
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(10, 8))
ax_handles = geokit.core.geom.drawGeoms(geoms=netherland_vector_complete, ax=axs[0, 0])
ax_handles = geokit.core.geom.drawGeoms(geoms=netherland_vector_0, ax=axs[0, 1])
ax_handles = geokit.core.geom.drawGeoms(geoms=netherland_vector_1, ax=axs[1, 0])
ax_handles = geokit.core.geom.drawGeoms(geoms=netherland_vector_2, ax=axs[1, 1])
Analyze Vector Data¶
In [5]:
Copied!
vinfo = geokit.core.vector.vectorInfo(gadm36_NLD_path)
# show information about the vector dataset
print("COUNT", vinfo.count)
print("SRS", vinfo.srs)
print("ATTRIBUTES", vinfo.attributes)
vinfo = geokit.core.vector.vectorInfo(gadm36_NLD_path)
# show information about the vector dataset
print("COUNT", vinfo.count)
print("SRS", vinfo.srs)
print("ATTRIBUTES", vinfo.attributes)
COUNT 491
SRS GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AXIS["Latitude",NORTH],
AXIS["Longitude",EAST],
AUTHORITY["EPSG","4326"]]
ATTRIBUTES ['GID_0', 'NAME_0', 'GID_1', 'NAME_1', 'NL_NAME_1', 'GID_2', 'NAME_2', 'VARNAME_2', 'NL_NAME_2', 'TYPE_2', 'ENGTYPE_2', 'CC_2', 'HASC_2']