def mosaic(images, outfile, vector): """ Mosaic multiple files together, but do not warp """ nd = images[0][0].NoDataValue() srs = images[0].Projection() # check they all have same projection filenames = [images[0].Filename()] for f in range(1, images.NumImages()): if images[f].Projection() != srs: raise Exception("Input files have non-matching projections and must be warped") filenames.append(images[f].Filename()) # transform vector to image projection geom = wktloads(transform_shape(vector.WKT(), vector.Projection(), srs)) extent = geom.bounds ullr = "%f %f %f %f" % (extent[0], extent[3], extent[2], extent[1]) # run merge command nodatastr = '-n %s -a_nodata %s -init %s' % (nd, nd, nd) cmd = 'gdal_merge.py -o %s -ul_lr %s %s %s' % (outfile, ullr, nodatastr, " ".join(filenames)) result = commands.getstatusoutput(cmd) VerboseOut('%s: %s' % (cmd, result), 4) imgout = gippy.GeoImage(outfile, True) for b in range(0, images[0].NumBands()): imgout[b].CopyMeta(images[0][b]) imgout.CopyColorTable(images[0]) return crop2vector(imgout, vector)
def mosaic(images, outfile, vector): """ Mosaic multiple files together, but do not warp """ nd = images[0][0].NoDataValue() srs = images[0].Projection() # check they all have same projection filenames = [images[0].Filename()] for f in range(1, images.NumImages()): if images[f].Projection() != srs: raise Exception( "Input files have non-matching projections and must be warped") filenames.append(images[f].Filename()) # transform vector to image projection geom = wktloads(transform_shape(vector.WKT(), vector.Projection(), srs)) extent = geom.bounds ullr = "%f %f %f %f" % (extent[0], extent[3], extent[2], extent[1]) # run merge command nodatastr = '-n %s -a_nodata %s -init %s' % (nd, nd, nd) cmd = 'gdal_merge.py -o %s -ul_lr %s %s %s' % (outfile, ullr, nodatastr, " ".join(filenames)) result = commands.getstatusoutput(cmd) VerboseOut('%s: %s' % (cmd, result), 4) imgout = gippy.GeoImage(outfile, True) for b in range(0, images[0].NumBands()): imgout[b].CopyMeta(images[0][b]) imgout.CopyColorTable(images[0]) return crop2vector(imgout, vector)
def test_just_missing_locations(self): with ContiguousRaggedTrajectoryProfile(self.nan_locations) as ml: t = ml.calculated_metadata() assert len(t.trajectories) == 1 traj = t.trajectories["clark-20150709T1803"] coords = list(wktloads(traj.geometry.wkt).coords) assert True not in [math.isnan(x) for x, y in coords] assert True not in [math.isnan(y) for x, y in coords]
def test_abstractmodel(self): _logger.info("Tests search geo_contains") dummy = self.env['test.dummy.from_abstract'].create({ 'name': 'test dummy', 'geo_line': wktloads(GEOLINE_1) }) dummy.write({ 'geo_multipolygon': 'LINE (0 0, 2 0, 2 2, 0 2, 0 0)', })
def setUp(self): super().setUp() # mock commit since it"s called in the _auto_init method self.cr.commit = mock.MagicMock() self.dummy = self.env['test.dummy'].create({ 'name': 'test dummy', 'geo_multipolygon': wktloads(MULTIPOLYGON_1) })
def test_func(self, cursor, uid, ids): """Test function only use for devel. TO DELETE""" print 'a = self.browse(cursor, uid, 1)' a = self.browse(cursor, uid, 1) print 'print a.name' print a.name print 'a.the_geom.area' print a.the_geom.area print 'shape_a = wktloads(a.the_geom.wkt)' shape_a = wktloads(a.the_geom.wkt) print 'tmp1 = Polygon([(0, 0), (1, 1), (1, 0)])' tmp1 = Polygon([(0, 0), (1, 1), (1, 0)]) print 'Polygon([(3, 0), (4, 1), (4, 0)])' tmp2 = Polygon([(3, 0), (4, 1), (4, 0)]) print 'shape_b = MultiPolygon([tmp1, tmp2])' shape_b = MultiPolygon([tmp1, tmp2]) print "a.write({'the_geom':shape_b})" a.write({'the_geom':shape_b}) print "self.browse(cursor, uid, 1)" a = self.browse(cursor, uid, 1) print "print a.the_geom.wkt" print a.the_geom.wkt print "a.write({'the_geom':shape_b})" a.write({'the_geom':shape_b}) print "a = self.browse(cursor, uid, 1)" a = self.browse(cursor, uid, 1) print "print a.the_geom" print a.the_geom print "a.write({'the_geom':shape_b.wkt})" a.write({'the_geom':shape_b.wkt}) print "a = self.browse(cursor, uid, 1)" a = self.browse(cursor, uid, 1) print "print a.the_geom.wkt" print a.the_geom.wkt print "a.write({'the_geom':geojson.dumps(shape_a)})" a.write({'the_geom':geojson.dumps(shape_a)}) print "a = self.browse(cursor, uid, 1)" a = self.browse(cursor, uid, 1) print "print a.the_geom.wkt" print a.the_geom.wkt b = self.create(cursor, uid, {'name':'1100', 'city': 'lausanne', 'the_geom': a.the_geom}) b = self.browse(cursor, uid, b) #self.unlink(cursor, uid, [b.id]) view_id = self.pool.get('ir.ui.view').search(cursor, uid,[('model', '=', 'dummy.zip'), ('type', '=', 'geoengine')])[0] import pprint; pprint.pprint(self.fields_view_get(cursor, uid, view_id=view_id, view_type='geoengine', context=None, toolbar=False, submenu=False)) import pprint; pprint.pprint(self.fields_view_get(cursor, uid, view_id=False, view_type='geoengine', context=None, toolbar=False, submenu=False)) print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_greater', Polygon([(3, 0), (4, 1), (4, 0)]))]) print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_greater', 0)]) print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_intersect', {'geoengine.demo.automatic.retailing.machine.the_point': []})]) print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_intersect', {'geoengine.demo.automatic.retailing.machine.the_point': [('name','!=','Vallorbe')]})]) return True
def test_crtp_just_missing_locations(self): axes = { 't': 'time', 'x': 'longitude', 'y': 'latitude', 'z': 'depth', } with ContiguousRaggedTrajectoryProfile(self.nan_locations) as ml: t = ml.calculated_metadata(axes=axes) assert len(t.trajectories) == 1 traj = t.trajectories["clark-20150709T1803"] coords = list(wktloads(traj.geometry.wkt).coords) assert True not in [math.isnan(x) for x, y in coords] assert True not in [math.isnan(y) for x, y in coords]
def setUp(self): common.TransactionCase.setUp(self) pool = RegistryManager.get(common.DB) class DummyModel(GeoModel): _name = 'test.dummy' _columns = { 'name': fields.char('ZIP', size=64, required=True), 'the_geom': fields.geo_multi_polygon('NPA Shape'), } # mock commit since it"s called in the _auto_init method self.cr.commit = mock.MagicMock() self.test_model = DummyModel.create_instance(pool, self.cr) self.test_model._auto_init(self.cr, {'module': __name__}) # create a view for our test.dummy model self.registry('ir.ui.view').create( self.cr, 1, { 'model': self.test_model._name, 'name': 'test.dummy.geo_view', 'arch': """<?xml version="1.0"?> <geoengine version="7.0"> <field name="name"/> </geoengine> """ }) self.registry('ir.ui.view').create( self.cr, 1, { 'model': self.test_model._name, 'name': 'test.dummy.form_view', 'arch': """<?xml version="1.0"?> <form string="Dummy"> <field name="name"/> <notebook colspan="4"> <page string="Geometry"> <field name="the_geom" colspan="4" widget="geo_edit_map"/> </page> </notebook> </form> """ }) self.dummy_id = self.test_model.create( self.cr, 1, {'name': 'test dummy', 'the_geom': wktloads(MULTIPOLYGON_1)})
def setUp(self): common.TransactionCase.setUp(self) class DummyModel(GeoModel): _name = 'test.dummy' _columns = { 'name': old_fields.char('ZIP', size=64, required=True), 'the_geom': old_fields.geo_multi_polygon('NPA Shape'), } class DummyModelRelated(GeoModel): _name = 'test.dummy.related' dummy_test_id = fields.Many2one( String='dummy_test', comodel_name='test.dummy') the_geom_related = geo_fields.GeoMultiPolygon( 'related', related='dummy_test_id.the_geom') # mock commit since it"s called in the _auto_init method self.cr.commit = mock.MagicMock() self.test_model = self._init_test_model(DummyModel) self.test_model_related = self._init_test_model(DummyModelRelated) # create a view for our test.dummy model self.registry('ir.ui.view').create( self.cr, 1, { 'model': self.test_model._name, 'name': 'test.dummy.geo_view', 'arch': """<?xml version="1.0"?> <geoengine> <field name="name"/> </geoengine> """ }) self.registry('ir.ui.view').create( self.cr, 1, { 'model': self.test_model._name, 'name': 'test.dummy.form_view', 'arch': """<?xml version="1.0"?> <form string="Dummy"> <field name="name"/> <notebook colspan="4"> <page string="Geometry"> <field name="the_geom" colspan="4" widget="geo_edit_map"/> </page> </notebook> </form> """ }) self.dummy_id = self.test_model.create( self.cr, 1, {'name': 'test dummy', 'the_geom': wktloads(MULTIPOLYGON_1)}) self.registry('ir.ui.view').create( self.cr, 1, { 'model': self.test_model_related._name, 'name': 'test.dummy.related.geo_view', 'arch': """<?xml version="1.0"?> <geoengine> <field name="dummy_test_id"/> </geoengine> """ })
def setUp(self): common.TransactionCase.setUp(self) class DummyModel(GeoModel): _name = 'test.dummy' _columns = { 'name': old_fields.char('ZIP', size=64, required=True), 'the_geom': old_fields.geo_multi_polygon('NPA Shape'), } class DummyModelRelated(GeoModel): _name = 'test.dummy.related' dummy_test_id = fields.Many2one(String='dummy_test', comodel_name='test.dummy') the_geom_related = geo_fields.GeoMultiPolygon( 'related', related='dummy_test_id.the_geom') # mock commit since it"s called in the _auto_init method self.cr.commit = mock.MagicMock() self.test_model = self._init_test_model(DummyModel) self.test_model_related = self._init_test_model(DummyModelRelated) # create a view for our test.dummy model self.registry('ir.ui.view').create( self.cr, 1, { 'model': self.test_model._name, 'name': 'test.dummy.geo_view', 'arch': """<?xml version="1.0"?> <geoengine> <field name="name"/> </geoengine> """ }) self.registry('ir.ui.view').create( self.cr, 1, { 'model': self.test_model._name, 'name': 'test.dummy.form_view', 'arch': """<?xml version="1.0"?> <form string="Dummy"> <field name="name"/> <notebook colspan="4"> <page string="Geometry"> <field name="the_geom" colspan="4" widget="geo_edit_map"/> </page> </notebook> </form> """ }) self.dummy_id = self.test_model.create( self.cr, 1, { 'name': 'test dummy', 'the_geom': wktloads(MULTIPOLYGON_1) }) self.registry('ir.ui.view').create( self.cr, 1, { 'model': self.test_model_related._name, 'name': 'test.dummy.related.geo_view', 'arch': """<?xml version="1.0"?> <geoengine> <field name="dummy_test_id"/> </geoengine> """ })
def setUp(self): common.TransactionCase.setUp(self) class DummyModel(GeoModel): _name = 'test.dummy' name = fields.Char(string="Zip", size=64, required=True) the_geom = geo_fields.GeoMultiPolygon(string="NPA Shape") geo_point = geo_fields.GeoPoint(string="Point") class DummyModelRelated(GeoModel): _name = 'test.dummy.related' dummy_test_id = fields.Many2one(String='dummy_test', comodel_name='test.dummy') the_geom_related = geo_fields.GeoMultiPolygon( 'related', related='dummy_test_id.the_geom') self.IrUiViewObj = self.env['ir.ui.view'] # mock commit since it"s called in the _auto_init method self.cr.commit = mock.MagicMock() self.test_model = self._init_test_model(DummyModel) self.test_model_related = self._init_test_model(DummyModelRelated) # create a view for our test.dummy model self.IrUiViewObj.create({ 'model': self.test_model._name, 'name': 'test.dummy.geo_view', 'arch': """<?xml version="1.0"?> <geoengine> <field name="name"/> </geoengine> """ }) self.IrUiViewObj.create({ 'model': self.test_model._name, 'name': 'test.dummy.form_view', 'arch': """<?xml version="1.0"?> <form string="Dummy"> <field name="name"/> <notebook colspan="4"> <page string="Geometry"> <field name="the_geom" colspan="4" widget="geo_edit_map"/> </page> </notebook> </form> """ }) self.dummy = self.test_model.create({ 'name': 'test dummy', 'the_geom': wktloads(MULTIPOLYGON_1) }) self.dummy_id = self.dummy.id self.IrUiViewObj.create({ 'model': self.test_model_related._name, 'name': 'test.dummy.related.geo_view', 'arch': """<?xml version="1.0"?> <geoengine> <field name="dummy_test_id"/> </geoengine> """ })
def test_func(self, cursor, uid, ids): """Test function only use for devel. TO DELETE""" print 'a = self.browse(cursor, uid, 1)' a = self.browse(cursor, uid, 1) print 'print a.name' print a.name print 'a.the_geom.area' print a.the_geom.area print 'shape_a = wktloads(a.the_geom.wkt)' shape_a = wktloads(a.the_geom.wkt) print 'tmp1 = Polygon([(0, 0), (1, 1), (1, 0)])' tmp1 = Polygon([(0, 0), (1, 1), (1, 0)]) print 'Polygon([(3, 0), (4, 1), (4, 0)])' tmp2 = Polygon([(3, 0), (4, 1), (4, 0)]) print 'shape_b = MultiPolygon([tmp1, tmp2])' shape_b = MultiPolygon([tmp1, tmp2]) print "a.write({'the_geom':shape_b})" a.write({'the_geom': shape_b}) print "self.browse(cursor, uid, 1)" a = self.browse(cursor, uid, 1) print "print a.the_geom.wkt" print a.the_geom.wkt print "a.write({'the_geom':shape_b})" a.write({'the_geom': shape_b}) print "a = self.browse(cursor, uid, 1)" a = self.browse(cursor, uid, 1) print "print a.the_geom" print a.the_geom print "a.write({'the_geom':shape_b.wkt})" a.write({'the_geom': shape_b.wkt}) print "a = self.browse(cursor, uid, 1)" a = self.browse(cursor, uid, 1) print "print a.the_geom.wkt" print a.the_geom.wkt print "a.write({'the_geom':geojson.dumps(shape_a)})" a.write({'the_geom': geojson.dumps(shape_a)}) print "a = self.browse(cursor, uid, 1)" a = self.browse(cursor, uid, 1) print "print a.the_geom.wkt" print a.the_geom.wkt b = self.create(cursor, uid, { 'name': '1100', 'city': 'lausanne', 'the_geom': a.the_geom }) b = self.browse(cursor, uid, b) #self.unlink(cursor, uid, [b.id]) view_id = self.pool.get('ir.ui.view').search( cursor, uid, [('model', '=', 'dummy.zip'), ('type', '=', 'geoengine')])[0] import pprint pprint.pprint( self.fields_view_get(cursor, uid, view_id=view_id, view_type='geoengine', context=None, toolbar=False, submenu=False)) import pprint pprint.pprint( self.fields_view_get(cursor, uid, view_id=False, view_type='geoengine', context=None, toolbar=False, submenu=False)) print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_greater', Polygon([(3, 0), (4, 1), (4, 0)]))]) print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_greater', 0)]) print self.geo_search( cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_intersect', { 'geoengine.demo.automatic.retailing.machine.the_point': [] })]) print self.geo_search( cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_intersect', { 'geoengine.demo.automatic.retailing.machine.the_point': [('name', '!=', 'Vallorbe')] })]) return True