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 = 'localhost', 
                              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(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.2.tar.gz (5.2 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: dbgeomparser-0.1.2.tar.gz
  • Upload date:
  • Size: 5.2 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.2.tar.gz
Algorithm Hash digest
SHA256 9238d8b05e7cd068d77fc4e6818d2453df16055435d67af2109b6ce6820b000b
MD5 5c5881912d425a6e2b55c81ff133bb0c
BLAKE2b-256 8a826555b3454055985c9e070ef682fa1a26e7e653401689436194d8a3b23f40

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