Skip to main content

A package to handle conversion of shapely geometries to Oracle database compatible geometry objects

Project description

Oracle Geometry Parser

A small package intended to convert shapely geometry objects to Oracle Spatial compatible geometry types for use in database insert pipelines following a geopandas or shapely analysis process.

Coordinate Reference Systems are supported and if passed as an argument, the resultant SDO geometry with be assigned the provided crs. This is only designed to work with 2D geometries. Shapely ignores the Z coordinate by default. If 3D data is parsed, the input into Oracle will be in 2D.

Requirements

Set Up

To set up, simply run pip install in a python command prompt:

pip install dbgeomparser

Example

The below code block depicts the a simple use case of the module - inserting a single shapely point geometry into an oracle table. Extentions of this methodology include parsing all geometries in a GeoDataFrame and inserting the entire dataset into an oracle table.

import oracledb
import shapely as shp
from dbgeomparser import OracleGeomParser

### Oracle Connection ###
connection = oracledb.connect(
    user = 'Your Username', 
    password = 'Your Password', 
    host = 'Your Host', 
    port = 1521, 
    dsn = 'Your dsn'
)
cursor = connection.cursor()

### Geometry Parser ###
parser = OracleGeomParser(connection) 

test_geometry = shp.Point(1, 1)
sdo_geom = parser.parse_geometry(test_geometry) 

# Can specify a crs if required by passing the parameter 'crs' as an argument 
# e.g. parser.parse_geometry(test_geometry, crs = 4326) where the value is an EPSG code.
# print(sdo_geom) will print something like this: 
# <oracledb.DbObject MDSYS.SDO_GEOMETRY at 0x2ae4d370170>
# indicating the conversion has been successful.

### Example Insert Statement ###
sql = "INSERT INTO SCHEMA_NAME.TABLE_NAME (GEOMETRY_COLUMN) VALUES (:1)"
cursor.execute(sql, [parser.parse_geometry(sdo_geom)])
connection.commit()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbgeomparser-0.1.11.tar.gz (6.7 kB view details)

Uploaded Source

File details

Details for the file dbgeomparser-0.1.11.tar.gz.

File metadata

  • Download URL: dbgeomparser-0.1.11.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for dbgeomparser-0.1.11.tar.gz
Algorithm Hash digest
SHA256 96582ced34e1ec9be526b195aae0949ca97a9e4152712a9ea6fe229b5c93a1d9
MD5 6b09f9f0cf8eb9fb4cecddfe6ec84594
BLAKE2b-256 06e25fc5e6c6cbbf89b2d7d79dc3c85af649b928957904600fbea83ae7dfe202

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page