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

Uploaded Source

File details

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

File metadata

  • Download URL: dbgeomparser-0.1.8.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.8.tar.gz
Algorithm Hash digest
SHA256 d275c39b09b60a19ae46c4f59a37eac3a5f306c083c361e2b87350b55ccf5aa8
MD5 cac94d51d732704e4d1b8a01cd89ddb5
BLAKE2b-256 b4e1f764432641d855ad23cbfccbd9aaf6e7983a498810695619e70cfa7252bf

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