On Sat, Sep 26, 2009 at 3:45 PM, Eric Lemoine
<[email protected]> wrote:
> On Sat, Sep 26, 2009 at 2:50 PM, Sanjiv Singh <[email protected]> wrote:
>> On Sat, Sep 26, 2009 at 5:13 PM, Eric Lemoine
>> <[email protected]> wrote:
>>> Hi
>>>
>>> (sorry if it's not the proper forum for this discussion, but I know
>>> there may interested people listening here :-)
>>
>> We are all part of the gispython "community", aren't we ;)
>>
>>>
>>> I'd like that MapFish rely on GeoAlchemy, to share code and development.
>>>
>>> For this, we need that GeoAlchemy reads database geometry values as
>>> objects implementing the __geo_interface__.
>>>
>>> The easiest would be to make GeoAlchemy create Shapely geometry
>>> objects. But I don't think it'd be a good idea to make GeoAlchemy
>>> depend on Shapely, because Shapely isn't a pure-Python lib.
>>>
>>> So I've been thinking about adding the boolean option "shape" to
>>> GeoAlchemy's TypeEngine (GeometryBase). If this option is true
>>> GeoAlchemy will create a Shapely geometry object using
>>> shapely.wrk.loads() and will add as a property to the
>>> PersistentSpatialElement object.
>>>
>>> What do you think?
>>>
>>
>> That would be great.
>> Is it possible to implement this as a separate package? That would
>> ease up dependency management.
>
> Could you elaborate?
>
> See attached patch to understand what I'm suggesting.
and FYI I got the read part of MapFish to work with GeoAlchemy with
only the attached patch to GeoAlchemy.
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : [email protected]
http://www.camptocamp.com
diff -r 3ef69b5712ce geoalchemy/base.py
--- a/geoalchemy/base.py Tue Sep 01 23:21:34 2009 +0530
+++ b/geoalchemy/base.py Sat Sep 26 15:55:35 2009 +0200
@@ -32,6 +32,7 @@
def __init__(self, desc):
self.desc = desc
+ self.shape = None
class WKTSpatialElement(SpatialElement, expression.Function):
"""Represents a Geometry value expressed within application code; i.e. in
@@ -72,10 +73,11 @@
name = 'GEOMETRY'
- def __init__(self, dimension=None, srid=4326, spatial_index=True, **kwargs):
+ def __init__(self, dimension=None, srid=4326, spatial_index=True, shape=False, **kwargs):
self.dimension = dimension
self.srid = srid
self.spatial_index = spatial_index
+ self.shape = shape
super(GeometryBase, self).__init__(**kwargs)
def bind_processor(self, dialect):
@@ -89,7 +91,11 @@
def result_processor(self, dialect):
def process(value):
if value is not None:
- return PersistentSpatialElement(value)
+ elt = PersistentSpatialElement(value)
+ if self.shape:
+ from shapely.wkb import loads
+ elt.shape = loads(value.decode('hex'))
+ return elt
else:
return value
return process
diff -r 3ef69b5712ce geoalchemy/geometry.py
--- a/geoalchemy/geometry.py Tue Sep 01 23:21:34 2009 +0530
+++ b/geoalchemy/geometry.py Sat Sep 26 15:55:35 2009 +0200
@@ -24,14 +24,22 @@
def result_processor(self, dialect):
def process(value):
if value is not None:
+ elt = None
if isinstance(dialect, PGDialect):
- return PGPersistentSpatialElement(value)
- if isinstance(dialect, SQLiteDialect):
- return SQLitePersistentSpatialElement(value)
- if isinstance(dialect, MySQLDialect):
- return MySQLPersistentSpatialElement(value)
+ elt = PGPersistentSpatialElement(value)
+ elif isinstance(dialect, SQLiteDialect):
+ elt = SQLitePersistentSpatialElement(value)
+ elif isinstance(dialect, MySQLDialect):
+ elt = MySQLPersistentSpatialElement(value)
else:
raise NotImplementedError
+ if self.shape:
+ # create a shapely geometry from the value
+ # and add as a property in the spatial
+ # element
+ from shapely.wkb import loads
+ elt.shape = loads(value.decode('hex'))
+ return elt
else:
return value
return process
_______________________________________________
Community mailing list
[email protected]
http://lists.gispython.org/mailman/listinfo/community