示例#1
0
 def __init__(self):
     super(TimerFixMemUsage, self).__init__()
     self.create_shp('building.shp')
     self.create_shp('building2.shp')
     self.obj = layer.ConsLayer('building.shp', 'building', 'ogr')
     self.obj2 = layer.ConsLayer('building2.shp', 'building', 'ogr')
     assert self.obj.isValid()
     assert self.obj2.isValid()
示例#2
0
 def process_tasks(self, source):
     self.get_tasks(source)
     for zoning in (self.rustic_zoning, self.urban_zoning):
         to_clean = []
         for zone in zoning.getFeatures():
             label = zone['label']
             comment = ' '.join((setup.changeset_tags['comment'],
                                 report.mun_code, report.mun_name, label))
             fn = os.path.join(self.path, 'tasks', label + '.shp')
             if os.path.exists(fn):
                 task = layer.ConsLayer(fn,
                                        label,
                                        'ogr',
                                        source_date=source.source_date)
                 if task.featureCount() > 0:
                     task_osm = task.to_osm(upload='yes',
                                            tags={'comment': comment})
                     del task
                     self.delete_shp(fn, False)
                     self.merge_address(task_osm, self.address_osm)
                     report.address_stats(task_osm)
                     report.cons_stats(task_osm, label)
                     fn = os.path.join('tasks', label + '.osm')
                     self.write_osm(task_osm, fn, compress=True)
                     report.osm_stats(task_osm)
             else:
                 to_clean.append(zone.id())
         if to_clean:
             zoning.writer.deleteFeatures(to_clean)
示例#3
0
 def get_building(self):
     """Merge building, parts and pools"""
     building_gml = self.cat.read("building")
     report.building_date = building_gml.source_date
     fn = os.path.join(self.path, 'building.shp')
     layer.ConsLayer.create_shp(fn, building_gml.crs())
     self.building = layer.ConsLayer(fn,
                                     providerLib='ogr',
                                     source_date=building_gml.source_date)
     self.building.append(building_gml)
     report.inp_buildings = building_gml.featureCount()
     report.inp_features = report.inp_buildings
     del building_gml
     part_gml = self.cat.read("buildingpart")
     self.building.append(part_gml)
     report.inp_parts = part_gml.featureCount()
     report.inp_features += report.inp_parts
     del part_gml
     other_gml = self.cat.read("otherconstruction", True)
     report.inp_pools = 0
     if other_gml:
         self.building.append(other_gml)
         report.inp_pools = other_gml.featureCount()
         report.inp_features += report.inp_pools
     del other_gml
示例#4
0
 def __init__(self):
     self.obj = layer.ConsLayer()
     mun = '38900'
     building_fn = BASEPATH + '{0}/A.ES.SDGC.BU.{0}.building.gml'.format(mun)
     buildingpart_fn = BASEPATH + '{0}/A.ES.SDGC.BU.{0}.buildingpart.gml'.format(mun)
     other_fn = BASEPATH + '{0}/A.ES.SDGC.BU.{0}.otherconstruction.gml'.format(mun)
     self.building_gml = QgsVectorLayer(building_fn, 'building', 'ogr')
     self.obj.append(self.building_gml)
     self.part_gml = QgsVectorLayer(buildingpart_fn, 'buildingpart', 'ogr')
     self.other_gml = QgsVectorLayer(other_fn, 'otherconstruction', 'ogr')
     QgsVectorFileWriter.writeAsVectorFormat(self.building_gml, 'temp.shp', "utf-8",
             self.building_gml.crs(), 'ESRI Shapefile')
     self.building_shp = QgsVectorLayer('temp.shp', 'building', 'ogr')
     c = self.building_gml.featureCount()
     #self.fids = [int(c*0.5) + i for i in range(50)]
     """
     self.zone = self.zoning_gml.getFeatures().next()
     self.request = QgsFeatureRequest().setFilterFids(self.fids)
     #self.test(self.get_features)
     #self.test(self.get_index)
     #self.fids = self.index.intersects(self.zone.geometry().boundingBox())
     osm_path = BASEPATH + mun + '/current_building.osm'
     fo = open(osm_path, 'r')
     self.current_bu_osm = osmxml.deserialize(fo)
     self.obj.reproject()
     print 'Seleccionando {} edificios de {}'.format(len(self.fids), c)
     self.test(self.get_fids_by_loop)
     """
     self.test(self.get_features)
     #self.test(self.get_index)
     self.test(self.get_index_shp)
     print '5 /', self.building_shp.featureCount()
     self.fids = [random.randrange(c) for i in range(5)]
     self.test(self.get_fids_by_dict_mem)
     self.test(self.get_fids_by_filter_shp)
     self.test(self.get_fids_by_filter_mem)
     print '50 /', self.building_shp.featureCount()
     self.fids = [random.randrange(c) for i in range(50)]
     self.test(self.get_fids_by_dict_mem)
     self.test(self.get_fids_by_filter_shp)
     self.test(self.get_fids_by_filter_mem)
     print '500 /', self.building_shp.featureCount()
     self.fids = [random.randrange(c) for i in range(500)]
     self.test(self.get_fids_by_dict_mem)
     self.test(self.get_fids_by_filter_shp)
     self.test(self.get_fids_by_filter_mem)
     print '5000 /', self.building_shp.featureCount()
     self.fids = [random.randrange(c) for i in range(5000)]
     self.test(self.get_fids_by_dict_mem)
     self.test(self.get_fids_by_filter_shp)
     self.test(self.get_fids_by_filter_mem)
     """
     self.test(self.get_fids_by_loop_mem)
     self.test(self.get_fid_by_fid)
     self.test(self.get_fids_by_select)
     self.test(self.get_fid_by_fid_mem)
     self.test(self.get_fids_by_select_mem)
     """
     QgsVectorFileWriter.deleteShapeFile('temp.shp')
示例#5
0
 def test_append_zone3(self):
     rprocessed = set()
     rindex = self.index
     rzone = self.rustic_zoning.getFeatures().next()
     task = layer.ConsLayer(baseName=rzone['label'])
     task.rename = {}
     refs = self.append_zone2(task, self.obj, rzone, rprocessed, rindex, True)
     print 'refs', len(refs)
     print task.featureCount()
示例#6
0
 def test_append_zone_1(self):
     rprocessed = set()
     rindex = self.index
     rzone = self.rustic_zoning.getFeatures().next()
     task = layer.ConsLayer(baseName=rzone['label'])
     task.rename = {}
     self.append_zone(task, self.obj, rzone, rprocessed, rindex)
     refs = set()
     for feat in task.getFeatures():
         refs.add(feat['localId'])
     print 'refs', len(refs)
     self.append_task(task, self.obj, refs)
     print task.featureCount()
示例#7
0
 def __init__(self):
     print 'start', datetime.now()
     d = time.time()
     super(BaseBuildingTimer, self).__init__()
     self.create_shp('building.shp')
     self.obj = layer.ConsLayer('building.shp', 'building', 'ogr')
     #self.obj = layer.ConsLayer()
     self.obj.append(self.building_gml)
     print 'building', 1000 * (time.time() - d), self.obj.featureCount()
     d = time.time()
     self.obj.append(self.part_gml)
     print 'parts', 1000 * (time.time() - d), self.obj.featureCount()
     d = time.time()
     self.obj.append(self.other_gml)
     print 'others', 1000 * (time.time() - d), self.obj.featureCount()
示例#8
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()
示例#9
0
 def get_tasks(self, source):
     base_path = os.path.join(self.path, 'tasks')
     if not os.path.exists(base_path):
         os.makedirs(base_path)
     else:
         for fn in os.listdir(base_path):
             os.remove(os.path.join(base_path, fn))
     tasks_r = 0
     tasks_u = 0
     last_task = ''
     to_add = []
     fcount = source.featureCount()
     for i, feat in enumerate(source.getFeatures()):
         label = feat['task'] if isinstance(feat['task'],
                                            basestring) else ''
         f = source.copy_feature(feat, {}, {})
         if i == fcount - 1 or last_task == '' or label == last_task:
             to_add.append(f)
         if i == fcount - 1 or (last_task != '' and label != last_task):
             fn = os.path.join(self.path, 'tasks', last_task + '.shp')
             if not os.path.exists(fn):
                 layer.ConsLayer.create_shp(fn, source.crs())
                 if last_task[0] == 'r':
                     tasks_r += 1
                 else:
                     tasks_u += 1
             task = layer.ConsLayer(fn,
                                    last_task,
                                    'ogr',
                                    source_date=source.source_date)
             task.writer.addFeatures(to_add)
             to_add = [f]
         last_task = label
     log.debug(_("Generated %d rustic and %d urban tasks files"), tasks_r,
               tasks_u)
     report.tasks_r = tasks_r
     report.tasks_u = tasks_u
示例#10
0
 def __init__(self):
     super(TimerShpLayer, self).__init__()
     self.create_shp('building.shp')
     self.obj = layer.ConsLayer('building.shp', 'building', 'ogr')
     assert self.obj.isValid()
示例#11
0
 def __init__(self):
     super(TimerBdLayer, self).__init__()
     self.create_bd('building.sqlite')
     self.obj = layer.ConsLayer('building.sqlite', 'building', 'ogr')
     assert self.obj.isValid()
示例#12
0
 def __init__(self):
     super(TimerMemLayer, self).__init__()
     self.obj = layer.ConsLayer()