Skip to content

Instantly share code, notes, and snippets.

@nbessi
Created September 7, 2011 14:54
Show Gist options
  • Save nbessi/1200785 to your computer and use it in GitHub Desktop.
Save nbessi/1200785 to your computer and use it in GitHub Desktop.
GeoEngine CRUD support phase 1
from shapely.wkt import dumps as wktdumps, loads as wktloads
from shapely.geometry import Polygon, MultiPolygon
import geojson
from base_geoengine import geo_model
class NPA(geo_model.GeoModel):
_inherit = "res.better.zip"
_columns = {
'the_geom' : fields.geo_multi_polygon('NPA Shape', required=False),
}
## then in PDB
a = self.browse(cursor, uid, 1)
print a.name
=>"name"
a.the_geom.area
=>1826016.15396
shape_a = wktloads(a.the_geom.wkt)
tmp1 = Polygon([(0, 0), (1, 1), (1, 0)])
tmp2 = Polygon([(3, 0), (4, 1), (4, 0)])
shape_b = MultiPolygon([tmp1, tmp2])
a.write({'the_geom':shape_b})
self.browse(cursor, uid, 1)
print a.the_geom.wkt
=>"MULTIPOLYGON (((0.0000000000000000 0.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)), ((3.0000000000000000 0.0000000000000000, 4.0000000000000000 1.0000000000000000, 4.0000000000000000 0.0000000000000000, 3.0000000000000000 0.0000000000000000)))"
a.write({'the_geom':shape_b})
a = self.browse(cursor, uid, 1)
print a.the_geom
=>"MULTIPOLYGON (((0.0000000000000000 0.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)), ((3.0000000000000000 0.0000000000000000, 4.0000000000000000 1.0000000000000000, 4.0000000000000000 0.0000000000000000, 3.0000000000000000 0.0000000000000000)))"
a.write({'the_geom':shape_b.wkt})
a = self.browse(cursor, uid, 1)
print a.the_geom.wkt
=>"MULTIPOLYGON (((0.0000000000000000 0.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)), ((3.0000000000000000 0.0000000000000000, 4.0000000000000000 1.0000000000000000, 4.0000000000000000 0.0000000000000000, 3.0000000000000000 0.0000000000000000)))"
a.write({'the_geom':geojson.dumps(shape_a)})
a = self.browse(cursor, uid, 1)
print a.the_geom.wkt
=>"MULTIPOLYGON (((737215.0276330610504374 5864353.8339319303631783, 737543.3877982229460031 5864783.7071054298430681, 737948.5267958140466362 5864552.5696083400398493, 738053.1263250419870019 5864679.8417055997997522, 738216.8857395290397108 5864613.1298964703455567, 738490.5394911790499464 5864624.5423330897465348, 738542.9542561250273138 5864450.5751003399491310, 739049.5560589859960601 5864338.1818904699757695, 738867.7566246089991182 5863984.2616126202046871, 738920.8373456969857216 5863971.5626628901809454, 738992.2938034459948540 5864091.7802356099709868, 739298.5344284039456397 5863935.5528446203097701, 739162.0679565919563174 5863688.4996618395671248, 738689.5895435370039195 5863929.3108004899695516, 738630.7952763630310073 5863862.3425974901765585, 739171.7144266630057245 5863538.7037500003352761, 739018.7339950030436739 5863461.3178858496248722, 738111.6977034270530567 5863485.1555565698072314, 737593.8555253560189158 5863635.9310693098232150, 737151.4909943189704791 5864046.0826191101223230, 737215.0276330610504374 5864353.8339319303631783)))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment