geoarrow / geoarrow-python

Python implementation of the GeoArrow specification
http://geoarrow.org/geoarrow-python/
Apache License 2.0
59 stars 3 forks source link

feat(geoarrow-types): Minimal type specifications #50

Closed paleolimbot closed 2 months ago

paleolimbot commented 3 months ago

A paired down version of #48. The scope of this PR is just to get the constants and parameterization of the type solidified along with how various components are combined (which is the powerful and annoying to replicate part).

import geoarrow.types as gt

user_request = gt.geoarrow()
user_request
# > TypeSpec(Encoding.GEOARROW)

inferred_from_data = gt.type_spec(
    dimensions="xy", geometry_type="point", edge_type="planar", crs=gt.OGC_CRS84
)
inferred_from_data
#> TypeSpec(GeometryType.POINT, Dimensions.XY, EdgeType.PLANAR, ProjJsonCrs(OGC:CRS84))

# Will error if a user typed a conflicting request (e.g., gt.linestring())
all_specified = gt.TypeSpec.coalesce_unspecified(user_request, inferred_from_data)
all_specified
#> TypeSpec(Encoding.GEOARROW, GeometryType.POINT, Dimensions.XY, EdgeType.PLANAR, ProjJsonCrs(OGC:CRS84))

# GeoPandas (or something else) can fill in defaults for things that were not specified
# or inferred but are required to create the full type
geopandas_defaults = gt.type_spec(
    encoding="wkb", coord_type="interleaved", edge_type="planar"
)
all_specified.with_defaults(geopandas_defaults)
#> TypeSpec(Encoding.GEOARROW, GeometryType.POINT, Dimensions.XY, CoordType.INTERLEAVED, EdgeType.PLANAR, ProjJsonCrs(OGC:CRS84))