Exemple #1
0
def addToUik(fileName, session, regionID=None):
    """
    Если указан regionID, то из файла импортируются УИКи данного региона.
    Внимание!!! Здесь не удаляются УИКи -- они должны быть удалены вместе с ТИКами.
    Если не указан regionID, то импортируется все УИКи.
    """
    processAll = (regionID==None)
    success = True
    dbsession = session
    with transaction.manager:
        shp = Reader(fileName)
        count_shapes = len(shp.shapes())
        records = shp.shapeRecords()
        shapes = shp.shapes()

        for i in range(count_shapes - 1):
            record = records[i]
            row = record.record
            if processAll or row[0] == regionID:
                prec = dbsession.query(GeocodingPrecision).filter_by(name=row[16]).one()
                uikRec = {
                    'region_id': row[0],
                    'tik_id': row[17],
                    'number_official': row[2],
                    'number_composite': '_'.join([str(row[17]), str(row[2])]),
                    'address_voting': row[3],
                    'place_voting': row[4],
                    'address_office': row[5],
                    'place_office': row[6],
                    'comment': row[8],
                    'geocoding_precision_id': prec.id,
                    'point' : "POINT(%s %s)" % (record.shape.points[0][0], record.shape.points[0][1])
                }

                uik = Uik()
                uik.number_official  = uikRec['number_official']
                uik.number_composite  = uikRec['number_composite']
                uik.address_voting  = uikRec['address_voting']
                uik.place_voting  = uikRec['place_voting']
                uik.address_office  = uikRec['address_office']
                uik.place_office  = uikRec['place_office']
                uik.comment  = uikRec['comment']
                uik.point  = WKTSpatialElement(uikRec['point'], 4326)
                uik.is_applied  = False
                uik.geocoding_precision_id  = uikRec['geocoding_precision_id']
                uik.tik_id  = uikRec['tik_id']
                uik.region_id  = uikRec['region_id']

                dbsession.add(uik)
    return success
Exemple #2
0
parser.add_option("--h", dest="host")
parser.add_option("--u", dest="user")
parser.add_option("--p", dest="password")
parser.add_option("--s", dest="shp_file")
parser.add_option("--c", dest="csv_file")
parser.add_option("--cm", dest="csv_file_mvd")

(options, args) = parser.parse_args()

# ----------------------------------------
# Read shp data of houses
# ----------------------------------------
from my_shapefile import Reader

print 'Reading houses shp file...'
shp = Reader(options.shp_file)
count_shapes = len(shp.shapes())
records = shp.shapeRecords()
shapes = shp.shapes()


def record_to_house(record):
    records = record.record
    return {
        'osm_id': records[0],
        'building': records[1],
        'street': records[2],
        'suburb': records[3],
        'house_num': records[4],
        'name': records[5],
        'address': records[7],
Exemple #3
0
parser.add_option("--u", dest="user")
parser.add_option("--p", dest="password")
parser.add_option("--s", dest="shp_file")
parser.add_option("--c", dest="csv_file")
parser.add_option("--cm", dest="csv_file_mvd")

(options, args) = parser.parse_args()


# ----------------------------------------
# Read shp data of houses
# ----------------------------------------
from my_shapefile import Reader

print 'Reading houses shp file...'
shp = Reader(options.shp_file)
count_shapes = len(shp.shapes())
records = shp.shapeRecords()
shapes = shp.shapes()


def record_to_house(record):
    records = record.record
    return {
        'osm_id': records[0],
        'building': records[1],
        'street': records[2],
        'suburb': records[3],
        'house_num': records[4],
        'name': records[5],
        'address': records[7],