Ejemplo n.º 1
0
def makeStateCounties():
	db = pg.Database( database = 'usageo_500k' )
	for level in ( '512', ):
		table = 'county_' + level
		fulltable = schema + '.' + table
		shpname = 'us2012-county-500k-%s' % level
		shpfile = '%(path)s/us2012/%(shpname)s/%(shpname)s.shp' %({
			'path': private.OUTPUT_SHAPEFILE_PATH,
			'shpname': shpname,
		})
		db.dropTable( fulltable )
		db.loadShapefile(
			shpfile, private.TEMP_PATH, fulltable,
			googGeom, '3857', 'LATIN1', True
		)
		#mergeStates( db, table, level )
		#writeEachState( db, table, level )
		writeEachStateCounties( db, fulltable, level )
		#db.connection.commit()
		#db.connection.close()
	#level = '512'
	#if level is not None:
	#	addLevel( db, table, level )
	#mergeCounties( db, level )
	#writeEachState( db, table, level )
	#writeAllStates( db, table, level )
	db.connection.commit()
	db.connection.close()
Ejemplo n.º 2
0
def makeDepartments():
    db = pg.Database(database='france2012')
    table = 'departement'
    #for level in ( None, 512, 1024, 2048, 4096, 8192, ):
    for level in (
            None,
            4096,
    ):
        if level is not None:
            addLevel(db, table, 'code_dept', level)
        mergeGeometries(
            db, 'france.departement', 'france.reg2012', level, '''
			WHERE
				france.departement.code_reg = france.reg2012.region
			AND
				substring(france.departement.code_reg from 1 for 1) != '0'
			GROUP BY
				france.departement.code_reg
		''')
        mergeGeometries(db, 'france.reg2012', 'france.france2012', level, '''
			WHERE
				true
		''')
        #mergeGeometries( db, table, level )
        #writeEachDepartment( db, table, level )
        writeAllDepartments(db, table, level)
    db.connection.commit()
    db.connection.close()
Ejemplo n.º 3
0
def main():
    db = pg.Database(database=database)
    loadNameTables(db)
    loadContinents(db)
    makeNation(db)
    db.connection.commit()
    db.connection.close()
Ejemplo n.º 4
0
def makeLegislative():
    db = pg.Database(database='france2012')
    table = 'legislative'
    #for level in ( None, 512, 1024, ):
    for level in (1024, ):
        if level is not None:
            addLevel(db, table, 'id_circo', level)
        mergeGeometries(
            db, 'france.legislative', 'france.departement', level, '''
			WHERE
				france.legislative.id_dep = france.departement.code_dept
			GROUP BY
				france.legislative.id_dep
		''')
        mergeGeometries(
            db, 'france.departement', 'france.reg2012', level, '''
			WHERE
				france.departement.code_reg = france.reg2012.region
			AND
				substring(france.departement.code_reg from 1 for 1) != '0'
			GROUP BY
				france.departement.code_reg
		''')
        mergeGeometries(db, 'france.reg2012', 'france.france2012', level, '''
			WHERE
				true
		''')
        #mergeGeometries( db, table, level )
        #writeEachLegislative( db, table, level )
        writeAllLegislative(db, table, level)
    db.connection.commit()
    db.connection.close()
Ejemplo n.º 5
0
def main():
    global db
    db = pg.Database(host=opt.hostname,
                     database=opt.database,
                     user=opt.username,
                     password=opt.password)
    process()
    db.connection.close()
Ejemplo n.º 6
0
def makeStatesNational():
	db = pg.Database( database = 'usageo_500k' )
	table = 'state'
	level = '4096'
	if level is not None:
		addLevel( db, table, level )
	mergeStates( db, table, level )
	#writeEachState( db, table, level )
	writeAllStates( db, table, level )
	db.connection.commit()
	db.connection.close()
Ejemplo n.º 7
0
def makeGopDetail():
	db = pg.Database( database = 'usageo_500k' )
	table = 'gop2012loc'
	level = '512'
	if level is not None:
		addLevel( db, table, level )
	mergeStates( db, table, level )
	writeEachState( db, table, level )
	writeAllStates( db, table, level )
	db.connection.commit()
	db.connection.close()
Ejemplo n.º 8
0
def makeMunis():
	db = pg.Database( database = database )
	createSchema( db, schema )
	for level in (
		#'full',
		'512',
		'1024',
	):
		munitable = schema + '.muni' + level
		provtable = schema + '.prov' + level
		nltable = schema + '.nl' + level
		
		db.dropTable( munitable )
		db.dropTable( provtable )
		db.dropTable( nltable )
		
		srcfile = 'nl2012-%s' % level
		filename = '../shapes/shp/%s/%s.shp' %( srcfile, srcfile )
		print 'Loading %s' % filename
		db.loadShapefile(
			filename, private.TEMP_PATH, munitable,
			geom, '3857', 'LATIN1', True
		)
		mergeGeometries( db, munitable, provtable,
			'prov',
			'''
				prov varchar(2)
			''', '''
				WHERE
					%(munitable)s.prov IS NOT NULL
				GROUP BY
					%(munitable)s.prov
			''' % {
				'munitable': munitable,
		})
		mergeGeometries( db, munitable, nltable,
			"'NL'",
			'''
				nation varchar(2)
			''', '''
				WHERE
					%(munitable)s.prov IS NOT NULL
			''' % {
				'munitable': munitable,
		})
		writeAllMunis( db, munitable, level )
	db.connection.commit()
	db.connection.close()
Ejemplo n.º 9
0
def makeLegimunes():
    db = pg.Database(database='france2012')
    table = 'legimune'
    for level in (None, ):
        if level is not None:
            addLevel(db, table, 'code_leg,code_comm', level)
        mergeGeometries(
            db, 'france.legimune', 'france.legislative', level, '''
			WHERE
				france.legimune.code_dept = france.legislative.id_dep
			AND
				france.legimune.code_leg = france.legislative.id_circo
			GROUP BY
				france.legimune.code_dept, france.legimune.code_leg
		''')
    writeEachLegislative(db, table, None)
    db.connection.commit()
    db.connection.close()
Ejemplo n.º 10
0
def makeCommunes():
    db = pg.Database(database='france2012')
    table = 'commune'
    for level in (
            None,
            128,
    ):
        if level is not None:
            addLevel(db, table, 'code_dept,code_comm', level)
        mergeGeometries(
            db, 'france.commune', 'france.departement', level, '''
			WHERE
				france.commune.code_dept = france.departement.code_dept
			GROUP BY
				france.commune.code_dept
		''')
    writeEachDepartment(db, table, None)
    db.connection.commit()
    db.connection.close()
Ejemplo n.º 11
0
def process():
    #db = pg.Database( database='postgres' )
    #db.createGeoDatabase( 'census' )
    #db.connection.close()

    db = pg.Database(database='census')
    #for year in '2000', '2010':
    for year in '2010', :
        schema = 'c' + year
        db.createSchema(schema)
        for kind in 'state', 'county', 'tract', 'bg':
            table = schema + '.' + kind
            create = True
            for state in states.array:
                fips = state['fips']
                print 'Loading', table, fips, state['name']
                zipfile = censusFileName(kind, year, fips)
                db.loadShapeZip(zipfile, private.TEMP_PATH, table, create)
                create = False
    db.connection.close()
Ejemplo n.º 12
0
def makeHouseNational():
	db = pg.Database( database = 'usageo_500k' )
	#level = '4096'
	#for level in '512', '4096':
	for level in ( '2048', ):
		table = 'house2012_' + level
		fulltable = schema + '.' + table
		shpname = 'us2012-house2012-%s' % level
		shpfile = '%(path)s/shp/us2012/%(shpname)s/%(shpname)s.shp' %({
			'path': private.OUTPUT_SHAPEFILE_PATH,
			'shpname': shpname,
		})
		db.dropTable( fulltable )
		db.loadShapefile(
			shpfile, private.TEMP_PATH, fulltable,
			googGeom, '3857', 'LATIN1', True #, None, tweakHouseSQL
		)
		#mergeStates( db, table, level )
		#writeEachState( db, table, level )
		writeAllStatesHouse( db, fulltable, level )
def process():
    #db = pg.Database( database='postgres' )
    #db.createGeoDatabase( 'turkey' )
    #db.connection.close()

    db = pg.Database(database='turkey')

    #db.createGeoDatabase( 'turkey' )

    schema = 't2011'
    db.createSchema(schema)
    db.connection.commit()

    loadProvinceFT(db, schema)
    loadDistrictFT(db, schema)

    #for level in '00 50 60 70 80 90'.split(' '):
    for level in '90'.split(' '):
        loadSHP(db, schema, 'districts', level)
        for tbl in (
                'provinces',
                'districts',
        ):
            #for tbl in ( 'provinces', ):
            name = tbl  # 'Turkey'
            table = '%s.%s' % (schema, tbl)
            gid = '-1'
            targetGeom = 'geom_' + level
            #boxGeom = 'geom_00'
            boxGeom = targetGeom
            #db.addGoogleGeometry( table, geom, googGeom )
            filename = '%s/turkey-%s-%s.jsonp' % (private.GEOJSON_PATH, tbl,
                                                  targetGeom)
            db.makeGeoJSON(filename, table, boxGeom, targetGeom, tbl, name,
                           gid, 'loadGeoJSON')

    db.connection.commit()
    db.connection.close()
Ejemplo n.º 14
0
def createDatabase( database ):
	print 'Creating database %s' % database
	db = pg.Database( database='postgres' )
	db.createGeoDatabase( database )
	db.connection.close()
Ejemplo n.º 15
0
def main():
	global db
	db = pg.Database( database='turkey' )
	process()
	db.connection.close()
	print 'Done!'
Ejemplo n.º 16
0
def main():
    db = pg.Database(database=database)
    loadContinents(db)
    makeRegions(db)
    db.connection.commit()
    db.connection.close()
Ejemplo n.º 17
0
def openDatabase():
    print 'Opening database %s' % database
    return pg.Database(database=database)
Ejemplo n.º 18
0
def main():
    global db
    db = pg.Database(database='census')
    process()
    db.connection.close()