def handle(self, *args, **kwargs): shape_file = args[0] ds = DataSource(shape_file) layer = ds[0] for feat in layer: try: area_id = feat['ID_0'].value except: area_id = feat['GADMID'].value area_name = unicode(feat['NAME_ENGLI'].value, 'iso-8859-1') area_varname = unicode(feat['NAME_LOCAL'].value, 'iso-8859-1') mpgeom = OGRGeometry('MultiPolygon') mpgeom.add(feat.geom) area_geom = GEOSGeometry(mpgeom.wkt) print "%s %s %s" % (area_id, area_name, area_varname) area = Area() area.shape_id = area_id area.name = area_name area.varname = area_varname area.type = 'Country' area.save() area.update_path() area.save() print "Tree ID: %d" % (area.tree_id,) areageom = Geom(area=area) areageom.geom = area_geom areageom.save()
def handle(self, *args, **kwargs): shape_file = args[0] ds = DataSource(shape_file) layer = ds[0] for feat in layer: try: area_id = feat['ID_0'].value except: area_id = feat['GADMID'].value area_name = unicode(feat['NAME_ENGLI'].value, 'iso-8859-1') area_varname = unicode(feat['NAME_LOCAL'].value, 'iso-8859-1') mpgeom = OGRGeometry('MultiPolygon') mpgeom.add(feat.geom) area_geom = GEOSGeometry(mpgeom.wkt) print "%s %s %s" % (area_id, area_name, area_varname) area = Area() area.shape_id = area_id area.name = area_name area.varname = area_varname area.type = 'Country' area.save() area.update_path() area.save() print "Tree ID: %d" % (area.tree_id, ) areageom = Geom(area=area) areageom.geom = area_geom areageom.save()
def handle(self, *args, **kwargs): tree_id = int(args[0]) level = int(args[1]) shape_file = args[2] ds = DataSource(shape_file) layer = ds[0] with Area.objects.delay_mptt_updates(): for feat in layer: parent_id = feat['ID_%s' % (level - 1, )].value area_id = feat['ID_%s' % level].value area_name = unicode(feat['NAME_%s' % level].value, 'iso-8859-1') try: area_varname = unicode(feat['VARNAME_%s' % level].value, 'iso-8859-1') except: area_varname = '' area_type = unicode(feat['TYPE_%s' % level].value, 'iso-8859-1') try: Area.objects.get(tree_id=tree_id, level=level, shape_id=area_id) except Area.DoesNotExist: pass else: continue mpgeom = OGRGeometry('MultiPolygon') mpgeom.add(feat.geom) area_geom = GEOSGeometry(mpgeom.wkt) print "%s (%s): %s (%s)" % (area_id, parent_id, area_name, area_type) area = Area() area.shape_id = area_id area.parent_id = Area.objects.get(tree_id=tree_id, level=(level - 1), shape_id=parent_id).pk area.name = area_name area.varname = area_varname area.type = area_type area.save() areageom = Geom(area=area) areageom.geom = area_geom areageom.save()
def handle(self, *args, **kwargs): tree_id = int(args[0]) level = int(args[1]) shape_file = args[2] ds = DataSource(shape_file) layer = ds[0] with Area.objects.delay_mptt_updates(): for feat in layer: parent_id = feat['ID_%s' % (level-1,)].value area_id = feat['ID_%s' % level].value area_name = unicode(feat['NAME_%s' % level].value, 'iso-8859-1') try: area_varname = unicode(feat['VARNAME_%s' % level].value, 'iso-8859-1') except: area_varname = '' area_type = unicode(feat['TYPE_%s' % level].value, 'iso-8859-1') try: Area.objects.get(tree_id=tree_id, level=level, shape_id=area_id) except Area.DoesNotExist: pass else: continue mpgeom = OGRGeometry('MultiPolygon') mpgeom.add(feat.geom) area_geom = GEOSGeometry(mpgeom.wkt) print "%s (%s): %s (%s)" % (area_id, parent_id, area_name, area_type) area = Area() area.shape_id = area_id area.parent_id = Area.objects.get(tree_id=tree_id, level=(level-1), shape_id=parent_id).pk area.name = area_name area.varname = area_varname area.type = area_type area.save() areageom = Geom(area=area) areageom.geom = area_geom areageom.save()
def handle(self, *args, **kwargs): level = int(args[0]) shape_file = args[1] ds = DataSource(shape_file) layer = ds[0] print layer.fields if level == 0: for feat in layer: area_id = feat['GADMID'].value area_name = feat['NAME_ENGLI'].value area_varname = feat['NAME_LOCAL'].value mpgeom = OGRGeometry('MultiPolygon') mpgeom.add(feat.geom) area_geom = GEOSGeometry(mpgeom.wkt) print "%s %s %s" % (area_id, area_name, area_varname) area = Area() area.id = area_id area.name = area_name area.varname = area_varname area.type = 'Country' area.save() areageom = Geom(area=area) areageom.geom = area_geom areageom.save() else: for feat in layer: parent_id = feat['ID_%s' % (level-1,)].value area_id = feat['ID_%s' % level].value area_name = unicode(feat['NAME_%s' % level].value, 'iso-8859-1') area_varname = unicode(feat['VARNAME_%s' % level].value, 'iso-8859-1') area_type = unicode(feat['TYPE_%s' % level].value, 'iso-8859-1') mpgeom = OGRGeometry('MultiPolygon') mpgeom.add(feat.geom) area_geom = GEOSGeometry(mpgeom.wkt) print "%s (%s): %s (%s)" % (area_id, parent_id, area_name, area_type) area = Area() area.id = area_id area.parent_id = parent_id area.name = area_name area.varname = area_varname area.type = area_type area.save() areageom = Geom(area=area) areageom.geom = area_geom areageom.save()
def handle(self, *args, **kwargs): level = int(args[0]) shape_file = args[1] ds = DataSource(shape_file) layer = ds[0] print layer.fields if level == 0: for feat in layer: area_id = feat['GADMID'].value area_name = feat['NAME_ENGLI'].value area_varname = feat['NAME_LOCAL'].value mpgeom = OGRGeometry('MultiPolygon') mpgeom.add(feat.geom) area_geom = GEOSGeometry(mpgeom.wkt) print "%s %s %s" % (area_id, area_name, area_varname) area = Area() area.id = area_id area.name = area_name area.varname = area_varname area.type = 'Country' area.save() areageom = Geom(area=area) areageom.geom = area_geom areageom.save() else: for feat in layer: parent_id = feat['ID_%s' % (level - 1, )].value area_id = feat['ID_%s' % level].value area_name = unicode(feat['NAME_%s' % level].value, 'iso-8859-1') area_varname = unicode(feat['VARNAME_%s' % level].value, 'iso-8859-1') area_type = unicode(feat['TYPE_%s' % level].value, 'iso-8859-1') mpgeom = OGRGeometry('MultiPolygon') mpgeom.add(feat.geom) area_geom = GEOSGeometry(mpgeom.wkt) print "%s (%s): %s (%s)" % (area_id, parent_id, area_name, area_type) area = Area() area.id = area_id area.parent_id = parent_id area.name = area_name area.varname = area_varname area.type = area_type area.save() areageom = Geom(area=area) areageom.geom = area_geom areageom.save()