Skip to content

Conversion

Jason Humber edited this page Jul 31, 2026 · 12 revisions

GeoPackage

export_features

Export features from a feature class to a new feature class optionally using a where clause and sorting the features.

from fudgeo import FeatureClass, GeoPackage
from pyproj import CRS
from spyops.conversion import Ascending, Descending, export_features
from spyops.environment import Extent, Setting
from spyops.environment.context import Swap

gpkg = GeoPackage('/some/path/world_features.gpkg')
source = gpkg['admin_a']
target = FeatureClass(gpkg, name='reordered_admin_a')

with (Swap(Setting.EXTENT, Extent.from_bounds(-180, -50, 0, 0, crs=CRS(4326))), 
      Swap(Setting.OUTPUT_COORDINATE_SYSTEM, CRS(3395))):
    fc = export_features(source, target=target, where_clause="""ISO_CC = 'BR'""", 
                         sort_fields=[Ascending('NAME'), Descending('ADMINTYPE')])

export_table

Export rows from a table to a new table optionally using a where clause and sorting the rows.

from fudgeo import GeoPackage, Table
from spyops.conversion import Ascending, Descending, export_table

gpkg = GeoPackage('/some/path/world_tables.gpkg')
source = gpkg['admin']
target = Table(gpkg, name='reordered_admin')

tbl = export_table(source, target=target, where_clause="""ISO_CC = 'AR'""", 
                   sort_fields=[Ascending('NAME'), Descending('ADMINTYPE')])

feature_class_to_geopackage

Copy one or more feature classes into a GeoPackage.

from fudgeo import GeoPackage, MemoryGeoPackage
from spyops.conversion import feature_class_to_geopackage
from spyops.environment import Setting
from spyops.environment.context import Swap

gpkg = GeoPackage('/some/path/ntdb_zm.gpkg')
mem = MemoryGeoPackage.create()
source = gpkg['hydro_a'], gpkg['hydro_zm_a']

with Swap(Setting.OVERWRITE, True):
    results = feature_class_to_geopackage(source, geopackage=mem)

table_to_geopackage

Copy one or more tables into a GeoPackage.

Feature classes can be included however no analysis settings or transformations are applied to the output.

from fudgeo import GeoPackage, MemoryGeoPackage
from spyops.conversion import table_to_geopackage
from spyops.environment import Setting
from spyops.environment.context import Swap

gpkg = GeoPackage('/some/path/ntdb_zm.gpkg')
mem = MemoryGeoPackage.create()
source = gpkg['hydro_a'], gpkg['hydro_zm_a']

with Swap(Setting.OVERWRITE, True):
    results = table_to_geopackage(source, geopackage=mem)

GPS

features_to_gpx

Convert features to the GPX format. Supported geometry types are point, multipoint, linestring, and multilinestring. Output coordinates will be in WGS84. Features can be filtered by extent and / or using a where clause.

from pathlib import Path
from fudgeo import GeoPackage
from spyops.conversion import features_to_gpx
from spyops.environment import Setting
from spyops.environment.context import Swap

gpkg = GeoPackage('/some/path/inputs.gpkg')
source = gpkg['gps_p']

with Swap(Setting.OVERWRITE, True):
    output_path = features_to_gpx(
        source, target=Path.home().joinpath('gps_p.gpx'), 
        name_field='name', description_field='system', date_field='dt')

gpx_to_features

Convert a GPX file to point features or line features. The point option converts waypoints and trackpoints, the line option (as_points=False) converts tracks.

from pathlib import Path
from fudgeo import FeatureClass, GeoPackage
from pyproj import CRS
from spyops.conversion import gpx_to_features
from spyops.environment import Setting
from spyops.environment.context import Swap

gpkg = GeoPackage('/some/path/inputs.gpkg')
target = FeatureClass(gpkg, name='gps_p')

with Swap(Setting.OUTPUT_COORDINATE_SYSTEM, CRS(3857)):
    gpx_to_features(Path.home().joinpath('gps_p.gpx'), target=target)

JSON

features_to_geojson

Convert a feature class to GeoJSON. The geometry and attributes of the feature class are included in the output.

The following options are supported:

  • Convert coordinates to WGS84 (default and recommended for GeoJSON)
  • Use formatted JSON output (default is compact)
  • Include Z values in the target if present in the source (default is to exclude Z)
  • Include M values in the target if present in the source (default is to exclude M)
  • Use aliases instead of field names for attributes in the target (default is use field names)
  • Subset the features to be included in the target using a where clause
from pathlib import Path
from fudgeo import GeoPackage
from spyops.conversion import features_to_geojson
from spyops.environment import Setting
from spyops.environment.context import Swap

gpkg = GeoPackage('/some/path/inputs.gpkg')
source = gpkg['gps_lcc_p']

with Swap(Setting.OVERWRITE, True):
    output_path = features_to_geojson(
        source, target=Path.home().joinpath('gps_p.geojson'))

geojson_to_features

Convert a GeoJSON file to a feature class. Use the geometry_type option to specify the geometry type of the target feature class. The default is to automatically determine the geometry type from the GeoJSON file.

from pathlib import Path
from fudgeo import FeatureClass, GeoPackage
from spyops.conversion import geojson_to_features

gpkg = GeoPackage('/some/path/inputs.gpkg')
target = FeatureClass(gpkg, name='airport_p')

geojson_to_features(Path.home().joinpath('point.geojson'), target=target)

Delimited File

delimited_file_to_table

Convert a delimited file to a table. Field names are derived from the file header.
Field data types are automatically guessed by sampling values in the file.

from pathlib import Path
from fudgeo import GeoPackage, Table
from spyops.conversion import delimited_file_to_table

gpkg = GeoPackage('/some/path/inputs.gpkg')
target = Table(gpkg, name='good')

delimited_file_to_table(Path.home().joinpath('good.csv'), target=target)

table_to_delimited_file

Export rows from a table or feature class to a delimited file optionally using a where clause, sorting the rows, and using field or alias names as the headers.

from pathlib import Path
from spyops.conversion import table_to_delimited_file

gpkg = GeoPackage('/some/path/inputs.gpkg')
source = FeatureClass(gpkg, name='airport_p')

table_to_delimited_file(source, target=Path.home().joinpath('airport_p.csv'))

Clone this wiki locally