Reputation: 1
There are some situations where the WKT format does not work (3D,4D geometries, arc in a geodetic). These are handled in Postgis EWKT format.
I have an out converter
def SDOOutConverter(DBobj):
if DBobj.SDO_ELEM_INFO:
sdo_elem = DBobj.SDO_ELEM_INFO.aslist()
else:
sdo_elem = None
if DBobj.SDO_ORDINATES:
sdo_ord = DBobj.SDO_ORDINATES.aslist()
else:
sdo_ord = None
return lSDO(
int(DBobj.SDO_GTYPE)
,DBobj.SDO_SRID
,sdo_elem
,sdo_ord
)
and the object definition.
class lSDO(object):
def __init__(self, gtype, srid, elemInfo, ordinates):
self.gtype = gtype
self.srid = int(srid or 0)
self.elemInfo = elemInfo
self.ordinates = ordinates
I have an example of returning the object information from a fixed query
cur.execute('select mkt_id, name, shape from hamster.cola_markets t')
for time_id, name, obj in cur:
sdo_type = obj.gtype
sdo_srid = obj.srid
sdo_elem = obj.elemInfo
sdo_ord = obj.ordinates
This takes the geometry column (shape) then in the for loop access the object.
Question: How would i do this dynamically. There are several tables with differing structures.
how would I write a dynamic for time_id, name, obj in cur:?
bonus question, How would one handle a table with multiple GEOMETRY columns?
I can crate a column list and tried using the string in the for loop
for '{}'.format(objcol) in cur:
results in:
for '{}'.format(objcol) in cur:
^^^^^^^^^^^^^^^^^^^
SyntaxError: cannot assign to function call
The problem I'm trying to solve is: replacing
cur.execute('select mkt_id, name, shape from hamster.cola_markets t')
for time_id, name, obj in cur:
with:
cur.execute('select * from {}.{}'.format(schema,tablename))
for [dynamic column list with obj reference] in cur:
In other words handle cursor procession dynamically.
Upvotes: 0
Views: 215
Reputation: 1
I'm going to partially answer my own question.
Part of my confusion is from the examples for sdo_geometries, without clear explanations.
With further experimenting i discovered that
cur.execute('select mkt_id, name, shape from hamster.cola_markets t')
for time_id, name, obj in cur:
is misleading. obj is just an alias for shape, so
sdo_type = obj.gtype
would work as well as
sdo_type = shape.gtype
So the problem for me was attributing some special meaning to obj, when what is does, at least for me, is obfuscates what is actually going on.
Documenting what is going on in code is helpful.
Upvotes: 0