예제 #1
0
def get_sector_list():
    dbcon = DatabaseConnector('chase')
    cur = dbcon.connect()
    cur.execute("""SELECT gid FROM sectors""")
    row = cur.fetchall()
    sector_list = [r[0] for r in row]
    return sector_list
예제 #2
0
def get_sector_list():
    dbcon = DatabaseConnector('chase')
    cur = dbcon.connect()
    cur.execute("""SELECT gid FROM sectors""")
    row = cur.fetchall()
    sector_list = [r[0] for r in row]
    return sector_list
예제 #3
0
 def __init__(self):
     dbcon = DatabaseConnector('chase')
     self.cur = dbcon.connect()
     return self.cur
예제 #4
0
#import osgeo.ogr
import os
import re
import datetime as dtime
import pytz
from database_connector import DatabaseConnector
import datetime

if __name__ == '__main__':
    dbcon = DatabaseConnector('chase2018')
    cur = dbcon.connect()


def shape_load(shape_path):
    """
    Loads shapes from given path to sectors table in WKT format in WGS84
    :param shape_path: path to shapefile
    :return: None
    """
    cur.execute("ALTER SEQUENCE sectors_id_seq RESTART WITH 1")  # zeroing id in table sectors
    shapefile = osgeo.ogr.Open(shape_path)  # open and read shapefile
    layer = shapefile.GetLayer(0)
    for i in range(layer.GetFeatureCount()):  # get features
        feature = layer.GetFeature(i)
        name = feature.GetField("STREFA").decode("utf-8")  # get field value
        num = feature.GetField("NUMER").decode("utf-8")
        wkt = feature.GetGeometryRef().ExportToWkt()  # export geometry to WKT
        cur.execute("INSERT INTO sectors (gid,shape,name) VALUES ('%s', ST_GeometryFromText('%s', 4326), '%s')" %
                    (num.encode("utf-8"), wkt, name.encode("UTF8")))  # write all the data into table

예제 #5
0
 def __init__(self):
     dbcon = DatabaseConnector('chase')
     self.cur = dbcon.connect()
     return self.cur
예제 #6
0
import osgeo.ogr
import os
import re
import datetime as dtime
import pytz
from database_connector import DatabaseConnector
import datetime

if __name__ == '__main__':
    dbcon = DatabaseConnector('chase')
    cur = dbcon.connect()


def shape_load(shape_path):
    """
    Loads shapes from given path to sectors table in WKT format in WGS84
    :param shape_path: path to shapefile
    :return: None
    """
    cur.execute("ALTER SEQUENCE sectors_id_seq RESTART WITH 1"
                )  # zeroing id in table sectors
    shapefile = osgeo.ogr.Open(shape_path)  # open and read shapefile
    layer = shapefile.GetLayer(0)
    for i in range(layer.GetFeatureCount()):  # get features
        feature = layer.GetFeature(i)
        name = feature.GetField("STREFA").decode("utf-8")  # get field value
        num = feature.GetField("NUMER").decode("utf-8")
        wkt = feature.GetGeometryRef().ExportToWkt()  # export geometry to WKT
        cur.execute(
            "INSERT INTO sectors (gid,shape,name) VALUES ('%s', ST_GeometryFromText('%s', 4326), '%s')"
            % (num.encode("utf-8"), wkt,