Éric Lemoine avatar Éric Lemoine committed a25a7f9

implement the "adapt" method in the geometry type engine

Comments (0)

Files changed (3)


     name = 'GEOMETRY'
-    def __init__(self, dimension=2, srid=4326, spatial_index=True, diminfo=None, **kwargs):
+    def __init__(self, dimension=2, srid=4326, spatial_index=True, **kwargs):
         self.dimension = dimension
         self.srid = srid
         self.spatial_index = spatial_index
-        self.diminfo = diminfo
         self.kwargs = kwargs
         super(GeometryBase, self).__init__()
         of DBSpatialElement"""
         return self.name
+    def adapt(self, cls, **kwargs):
+        return cls(dimension=self.dimension, srid=self.srid,
+                   spatial_index=self.spatial_index,
+                   **self.kwargs)
 # ORM integration
 def _to_gis(value, srid_db):


     def process_result(self, value, type):
         value = self.process_wkb(value)
         wkb_element = WKBSpatialElement(value, type.srid, type.name)    
-        if type.diminfo:
+        if type.kwargs.has_key("diminfo"):
             # also set the DIMINFO data so that in can be used in function calls, see DimInfoFunction()
-            if not hasattr(type, 'diminfo_sql'):
+            if not type.kwargs.has_key("diminfo_sql"):
                 # cache the SQLAlchemy text literal
-                type.diminfo_sql = text(type.diminfo)
-            wkb_element.DIMINFO = type.diminfo_sql
+                type.kwargs["diminfo_sql"] = text(type.kwargs["diminfo"])
+            wkb_element.DIMINFO = type.kwargs["diminfo_sql"]
         return OraclePersistentSpatialElement(wkb_element)
         bind.execute("DELETE FROM USER_SDO_GEOM_METADATA WHERE table_name = '%s' AND column_name = '%s'" %
                             (table.name.upper(), column.name.upper()))
-        if column.type.spatial_index and column.type.diminfo:
+        if column.type.spatial_index and column.type.kwargs.has_key("diminfo"):
             bind.execute("DROP INDEX %s_%s_sidx" % (table.name, column.name))
     def handle_ddl_after_create(self, bind, table, column):    
             bind.execute("ALTER TABLE %s MODIFY %s NOT NULL" % (table.name, column.name))
-        if not column.type.diminfo:
+        if not column.type.kwargs.has_key("diminfo"):
             warnings.warn("No DIMINFO given for '%s.%s', no entry in USER_SDO_GEOM_METADATA will be made "\
                     "and no spatial index will be created." % (table.name, column.name), 
                     exc.SAWarning, stacklevel=3)
-            diminfo = column.type.diminfo
+            diminfo = column.type.kwargs["diminfo"]
             bind.execute("INSERT INTO USER_SDO_GEOM_METADATA (table_name, column_name, diminfo, srid) " +
                             "VALUES ('%s', '%s', %s, %s)" % 


 import cx_Oracle
 #engine = create_engine('oracle://gis:gis@localhost:1521/gis', echo=True)
-engine = create_engine('oracle://system:system@', echo=False)
+engine = create_engine('oracle://system:system@', echo=False)
 metadata = MetaData(engine)
 session = sessionmaker(bind=engine)()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.