Okay, well I have a working solution. Assuming geojson is my dict, the code becomes
>>> wkb.loads(asShape(geojson).to_wkb()) <shapely.geometry.point.Point object at 0x1faead0> Douglas Mayle On May 19, 2009, at 9:56 AM, Douglas Mayle wrote: > A little bit more context. I've got a GeoJSON geometry coming back > from the client side, I call asShape, and it returns the > PointAdapter. I'm assigning that PointAdapter to a SQLAlchemy model > instance, which is saving it to the database. In certain > circumstances, I need to save that model instance to a session, rather > than the database. Is there something else I should be using instead > of asShape and PointAdapters ? > > Doug > > On May 18, 2009, at 6:44 PM, Sean Gillies wrote: > >> I'd be really surprised if pickling point adapters worked. At the >> very >> least, you'd have to pickle the object they wrap too, and that starts >> to get beyond their scope. They are really only about temporarily >> wrapping other long-lived objects. Pickle their context and then re- >> wrap as needed. >> >> Sean >> >> On May 18, 2009, at 4:27 PM, Douglas Mayle wrote: >> >>> Also, I don't know if you addressed the serialization as well. I >>> added: >>> >>> def __reduce__(self): >>> return (self.__class__, (self.context,), self.to_wkb()) >>> >>> to the PointAdapter class, which seems to take care of the issue... >>> (I tested this by checking out 1.0.12) >>> >>> Douglas Mayle >>> >>> On May 18, 2009, at 6:03 PM, Sean Gillies wrote: >>> >>>> I've just fixed this bug and upload a4 eggs to my index. Care to >>>> try >>>> again? >>>> >>>> More notes at http://sgillies.net/blog/900/diving-into-shapely-1-1. >>>> >>>> Cheers, >>>> Sean >>>> >>>> On May 18, 2009, at 3:09 PM, Douglas Mayle wrote: >>>> >>>>> Hi all, >>>>> I'm having some trouble pickling shapely geometry objects. After >>>>> saving a shapely geometry object in my beaker session (which >>>>> pickles >>>>> the object, I am unable to reload it from the database) This is >>>>> the >>>>> error I'm getting: >>>>> >>>>>>>> import cPickle >>>>>>>> >>>>> cPickle >>>>> .loads("(dp1\nS'session'\np2\n(dp3\nS'media'\np4\n(lp5\nccopy_reg >>>>> \n_reconstructor\np6\n(ccommunityalmanac.model.almanac\nStory >>>>> \np7\nc__builtin__\nobject >>>>> \np8\nNtRp9\n(dp10\nS'text'\np11\nVsadfsfd >>>>> \np12\nsS'_sa_instance_state'\np13\ng6\n(csqlalchemy.orm.identity >>>>> \nIdentityManagedState >>>>> \np14\ng8\nNtRp15\n(dp16\nS'modified'\np17\nI01\nsS'committed_state'\np18\n(dp19\ng11\ncsqlalchemy.util\nsymbol\np20\n(S'NO_VALUE'\np21\ntRp22\nsS'order'\np23\ng22\nssS'instance'\np24\ng9\nsS'callables'\np25\n(dp26\nsS'parents'\np27\n(dp28\nsS'key'\np29\nNsS'expired_attributes'\np30\nc__builtin__\nfrozenset\np31\n((ltRp32\nsS'expired'\np33\nI00\nsS'pending'\np34\n(dp35\nsbsg23\nI0\nsS'id'\np36\nNsbag6\n(ccommunityalmanac.model.almanac\nMap\np37\ng8\nNtRp38\n(dp39\nS'_sa_instance_state'\np40\ng6\n(g14\ng8\nNtRp41\n(dp42\ng17\nI01\nsg18\n(dp43\nS'location'\np44\ng22\nsS'order'\np45\ng22\nssg24\ng38\nsg25\n(dp46\nsg27\n(dp47\nsg29\nNsg30\ng32\nsg33\nI00\nsg34\n(dp48\nsbsg44\ncshapely.geometry.point\nPointAdapter\np49\n(tRp50\nS'\\x01\\x01\\x00\\x00\\x00\\x00\\xa8\\xb2\\x91\\x1ex_\\xc1I\\x8d%\\xb10\\xf0RA'\nbsg45\nI1\nsbasS'_accessed_time'\np51\nF1242679546.0185621\nsS'_creation_time'\np52\nF1242679454.1160531\nss." >>>>> ... ) >>>>> Traceback (most recent call last): >>>>> File "<stdin>", line 1, in <module> >>>>> TypeError: ('__init__() takes exactly 2 arguments (1 given)', >>>>> <class >>>>> 'shapely.geometry.point.PointAdapter'>, ()) >>>>>>>> >>>>> >>>>> I wanted to check to see if it was just fixed in trunk, but I'm >>>>> unable >>>>> to run trunk because util seems to have disappeared: >>>>> Launching server process >>>>> /Users/douglas/Projects/almanacpylons/lib/python2.5/site-packages/ >>>>> Shapely-1.1a3-py2.5.egg/shapely/implementation.py:40: >>>>> ImplementationWarning: no installed plugin package matches >>>>> requirements shapely.geos>=1.0a3 >>>>> warn("no installed plugin package matches requirements %s" % >>>>> str(e), ImplementationWarning) >>>>> Traceback (most recent call last): >>>>> File "/Users/douglas/Projects/almanacpylons/bin/ca", line 22, in >>>>> <module> >>>>> main() >>>>> File "/Users/douglas/Projects/almanacpylons/src/communityalmanac/ >>>>> communityalmanac/commands.py", line 184, in main >>>>> from communityalmanac.config.middleware import make_app >>>>> File "/Users/douglas/Projects/almanacpylons/src/communityalmanac/ >>>>> communityalmanac/config/middleware.py", line 31, in <module> >>>>> from communityalmanac.config.environment import load_environment >>>>> File "/Users/douglas/Projects/almanacpylons/src/communityalmanac/ >>>>> communityalmanac/config/environment.py", line 29, in <module> >>>>> import communityalmanac.lib.helpers >>>>> File "/Users/douglas/Projects/almanacpylons/src/communityalmanac/ >>>>> communityalmanac/lib/helpers.py", line 25, in <module> >>>>> from communityalmanac.lib.base import render >>>>> File "/Users/douglas/Projects/almanacpylons/src/communityalmanac/ >>>>> communityalmanac/lib/base.py", line 27, in <module> >>>>> from communityalmanac.model import meta >>>>> File "/Users/douglas/Projects/almanacpylons/src/communityalmanac/ >>>>> communityalmanac/model/__init__.py", line 38, in <module> >>>>> from communityalmanac.model.almanac import Almanac, Page, User, >>>>> Media, PDF, Sound, Image, Story, Map, Comment >>>>> File "/Users/douglas/Projects/almanacpylons/src/communityalmanac/ >>>>> communityalmanac/model/almanac.py", line 25, in <module> >>>>> from sqlgeotypes import POINT >>>>> File "/Users/douglas/Projects/almanacpylons/src/communityalmanac/ >>>>> communityalmanac/model/sqlgeotypes.py", line 3, in <module> >>>>> from shapely import geometry, wkb >>>>> File "/Users/douglas/Projects/almanacpylons/lib/python2.5/site- >>>>> packages/Shapely-1.1a3-py2.5.egg/shapely/geometry/__init__.py", >>>>> line >>>>> 20, in <module> >>>>> from point import Point, asPoint >>>>> File "/Users/douglas/Projects/almanacpylons/lib/python2.5/site- >>>>> packages/Shapely-1.1a3-py2.5.egg/shapely/geometry/point.py", line >>>>> 10, >>>>> in <module> >>>>> from shapely.geometry.utils import coord_seq >>>>> ImportError: No module named utils >>>>> >>>>> Thanks, >>>>> Douglas Mayle >>>>> >>>>> >>>>> _______________________________________________ >>>>> Community mailing list >>>>> [email protected] >>>>> http://lists.gispython.org/mailman/listinfo/community >>>> >>>> _______________________________________________ >>>> Community mailing list >>>> [email protected] >>>> http://lists.gispython.org/mailman/listinfo/community >>> >>> _______________________________________________ >>> Community mailing list >>> [email protected] >>> http://lists.gispython.org/mailman/listinfo/community >> >> _______________________________________________ >> Community mailing list >> [email protected] >> http://lists.gispython.org/mailman/listinfo/community > > _______________________________________________ > Community mailing list > [email protected] > http://lists.gispython.org/mailman/listinfo/community _______________________________________________ Community mailing list [email protected] http://lists.gispython.org/mailman/listinfo/community
