Skip to content

Commit

Permalink
new insert_srid arg, and assert self.srid is not None for writes
Browse files Browse the repository at this point in the history
  • Loading branch information
floptical committed Aug 16, 2024
1 parent 7eb7f06 commit 7b7875b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion geopetl/oracle_sde.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ def _get_srid(self):
if self.geom_field is None:
return None

# Someone wants to force the SRID to be detected as this.
if self.insert_srid:
return self.insert_srid

stmt = """
select s.auth_srid
from sde.layers l
Expand Down Expand Up @@ -960,6 +964,11 @@ def write(self, rows, srid=None, table_srid=None,
for field in fields:
type_ = type_map[field]
if type_ == 'geom':
# SRID cannot be None here! This will result in this being used in the prepare statment:
#SDE.ST_GEOMETRY(:SHAPE, NONE))
# which ends with this error: cx_Oracle.DatabaseError: ORA-00984: column not allowed here
print('Making sure we have an SRID value..')
assert self.srid, "SRID cannot be None for the write method!"
geom_placeholder = 'SDE.ST_Geometry(:{}, {})'\
.format(field, self.srid)
placeholders.append(geom_placeholder)
Expand Down Expand Up @@ -1011,6 +1020,7 @@ def write(self, rows, srid=None, table_srid=None,
stmt_fields_joined = ', '.join(stmt_fields)
prepare_stmt = "INSERT INTO {} ({}) VALUES ({})".format(self._name_with_schema, \
stmt_fields_joined, placeholders_joined)
print(f'prepare_stmt: {prepare_stmt}')
self.db.cursor.prepare(prepare_stmt)

db_types_filtered = {x.upper(): db_types.get(x.upper()) for x in stmt_fields if x != self.objectid_field}
Expand Down Expand Up @@ -1095,13 +1105,14 @@ def count(self):
################################################################################

class OracleSdeQuery(SpatialQuery):
def __init__(self, db, table, fields=None, return_geom=True, to_srid=None,
def __init__(self, db, table, fields=None, return_geom=True, to_srid=None, insert_srid=None,
where=None, limit=None, timestamp=False, geom_with_srid=False, sql=None):
self.db = db
self.table = table
self.fields = fields
self.return_geom = return_geom
self.to_srid = to_srid
self.insert_srid = insert_srid
self.where = where
self.limit = limit
self.timestamp = timestamp
Expand Down

0 comments on commit 7b7875b

Please sign in to comment.