예제 #1
0
 def get_zoning(self):
     """
     Reads cadastralzoning and splits in 'MANZANA' (urban) and 'POLIGONO'
     (rustic)
     """
     zoning_gml = self.cat.read("cadastralzoning")
     fn = os.path.join(self.path, 'rustic_zoning.shp')
     layer.ZoningLayer.create_shp(fn, zoning_gml.crs())
     self.rustic_zoning = layer.ZoningLayer('r{:03}', fn, 'rusticzoning',
                                            'ogr')
     self.rustic_zoning.append(zoning_gml, level='P')
     self.cat.get_boundary(self.rustic_zoning)
     report.cat_mun = self.cat.cat_mun
     report.mun_name = getattr(self.cat, 'boundary_name', None)
     report.mun_area = round(self.rustic_zoning.get_area() / 1E6, 1)
     if hasattr(self.cat, 'boundary_data'):
         if 'wikipedia' in self.cat.boundary_data:
             report.mun_wikipedia = self.cat.boundary_data['wikipedia']
         if 'wikidata' in self.cat.boundary_data:
             report.mun_wikidata = self.cat.boundary_data['wikidata']
         if 'population' in self.cat.boundary_data:
             report.mun_population = (self.cat.boundary_data['population'],
                                      self.cat.boundary_data.get(
                                          'population:date', '?'))
     if self.options.tasks or self.options.zoning:
         fn = os.path.join(self.path, 'urban_zoning.shp')
         layer.ZoningLayer.create_shp(fn, zoning_gml.crs())
         self.urban_zoning = layer.ZoningLayer('u{:05}', fn, 'urbanzoning',
                                               'ogr')
         self.urban_zoning.append(zoning_gml, level='M')
     del zoning_gml
예제 #2
0
 def __init__(self):
     super(AppendZoneTimer, self).__init__()
     d = time.time()
     self.index = QgsSpatialIndex(self.obj.getFeatures())
     print 'index', 1000 * (time.time() - d)
     d = time.time()
     zoning_fn = BASEPATH + '{0}/A.ES.SDGC.CP.{0}.cadastralzoning.gml'.format(self.mun)
     zoning_gml = QgsVectorLayer(zoning_fn, 'zoning', 'ogr')
     self.urban_zoning = layer.ZoningLayer(baseName='urbanzoning')
     self.rustic_zoning = layer.ZoningLayer(baseName='rusticzoning')
     self.urban_zoning.append(zoning_gml, level='M')
     print 'urban_zoning', 1000 * (time.time() - d), self.urban_zoning.featureCount()
     d = time.time()
     self.rustic_zoning.append(zoning_gml, level='P')
     print 'rustic_zoning', 1000 * (time.time() - d), self.rustic_zoning.featureCount()
예제 #3
0
 def _test_copy(self):
     fn1 = 'urban_zoning.shp'
     fn2 = 'rustic_zoning.shp'
     fields = self.zoning_gml.pendingFields()
     attrs = [fields.indexFromName('levelName'), fields.indexFromName('label')]
     QgsVectorFileWriter.writeAsVectorFormat(self.zoning_gml, fn1, 'utf-8', 
         self.zoning_gml.crs(), 'ESRI Shapefile', attributes=attrs,
         forceMulti=True, overrideGeometryType=QgsWKBTypes.Polygon)
     layer1 = layer.ZoningLayer(fn1, 'urban_zoning', 'ogr')
     layer1.selectByExpression("levelName like '%POLIGONO%'")
     QgsVectorFileWriter.writeAsVectorFormat(layer1, fn2, 'utf-8', 
         layer1.crs(), 'ESRI Shapefile', onlySelected=True)
     layer2 = layer.ZoningLayer(fn2, 'rustic_zoning', 'ogr')
     layer1.writer.deleteFeatures(layer1.selectedFeaturesIds())
     QgsVectorFileWriter.deleteShapeFile(fn1)
     QgsVectorFileWriter.deleteShapeFile(fn2)
예제 #4
0
 def test_multi(self):
     """Some multisurface features in zoning gml are wrongly converted to polygons"""
     fn = 'urban_zoning.shp'
     layer.ZoningLayer.create_shp(fn, self.zoning_gml.crs())
     urban = layer.ZoningLayer(fn, 'zoning', 'ogr')
     fixture = QgsVectorLayer('test/zoning.gml', 'zoning', 'ogr')
     exp = QgsExpression("inspireId_localId = '69297CS5262N'")
     request = QgsFeatureRequest(exp)
     f = fixture.getFeatures(request).next()
     g = f.geometry()
     print 'multipolygon', [[[len(r)] for r in p] for p in g.asMultiPolygon()]
     urban.writer.addFeatures([f])
     f = urban.getFeatures().next()
     g = f.geometry()
     print 'to wrong polygon', [len(r) for r in g.asPolygon()]
     QgsVectorFileWriter.deleteShapeFile(fn)
예제 #5
0
 def _test_zoning(self):
     print 'start', datetime.now()
     d = time.time()
     #urban_zoning = layer.ZoningLayer(baseName='urbanzoning')
     rustic_zoning = layer.ZoningLayer(baseName='rusticzoning')
     #urban_zoning.append(self.zoning_gml, level='M')
     rustic_zoning.append(self.zoning_gml, level='P')
     #print 'urban', urban_zoning.featureCount()
     print 'rustic', rustic_zoning.featureCount()
     index = QgsSpatialIndex(self.building_gml.getFeatures())
     #indexp = QgsSpatialIndex(self.part_gml.getFeatures())
     #indexo = QgsSpatialIndex(self.other_gml.getFeatures())
     print 'index', 1000 * (time.time() - d)
     d = time.time()
     i = 0
     processed = set()
     for zone in rustic_zoning.getFeatures():
         i += 1
         refs = set()
         task = layer.ConsLayer(baseName=zone['label'])
         task.append_zone(self.building_gml, zone, processed, index)
         print 'zone', 1000 * (time.time() - d), i
         d = time.time()
         for feat in task.getFeatures():
             refs.add(feat['localId'])
         #print 'refs', 1000 * (time.time() - d)
         #d = time.time()
         task.append_task(self.part_gml, refs)
         #task.append_zone(self.part_gml, zone, processed, indexp)
         print 'part', 1000 * (time.time() - d)
         d = time.time()
         task.append_task(self.other_gml, refs)
         #task.append_zone(self.other_gml, zone, processed, indexp)
         print 'other', 1000 * (time.time() - d)
         d = time.time()
         processed = processed.union(refs)
         del task
         print i
         if i > 0: break
     print 'end', datetime.now()
예제 #6
0
 def _test_mem(self):
     layer1 = layer.ZoningLayer()
     layer1.append(self.zoning_gml, 'M')
     layer2 = layer.ZoningLayer()
     layer2.append(self.zoning_gml, 'P')
예제 #7
0
 def _test_append_rustic(self):
     fn = 'rustic_zoning.shp'
     layer.ZoningLayer.create_shp(fn, self.zoning_gml.crs())
     rustic = layer.ZoningLayer(fn, 'zoning', 'ogr')
     rustic.append(self.zoning_gml, 'M')
     QgsVectorFileWriter.deleteShapeFile(fn)
예제 #8
0
 def _test_append_urban(self):
     fn = 'urban_zoning.shp'
     layer.ZoningLayer.create_shp(fn, self.zoning_gml.crs())
     urban = layer.ZoningLayer(fn, 'zoning', 'ogr')
     urban.append(self.zoning_gml, 'M')
     QgsVectorFileWriter.deleteShapeFile(fn)
예제 #9
0
 def __init__(self):
     mun = '28900'
     zoning_fn = BASEPATH + '{0}/A.ES.SDGC.CP.{0}.cadastralzoning.gml'.format(mun)
     self.zoning_gml = QgsVectorLayer(zoning_fn, 'zoning', 'ogr')
     layer.ZoningLayer.create_shp('urban_zoning.shp', self.zoning_gml.crs())
     self.obj = layer.ZoningLayer()