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(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.6.tar.gz (6.6 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: dbgeomparser-0.1.6.tar.gz
  • Upload date:
  • Size: 6.6 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.6.tar.gz
Algorithm Hash digest
SHA256 a325357d08f71c1737c369edc7098dbc5d1f79a48a55a59137d22f48bea5c063
MD5 92b7fd6385ea3e7658f1c0e8b7dee591
BLAKE2b-256 fc7434d4df9cae96f079709ac76783cd02bcf00ce55ae0f6cd5b55372548014a

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