-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f15b8dd
commit 1722b3b
Showing
3 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/bash | ||
|
||
# script downloads shape files from GADM, make sure you're connected to internet | ||
wget https://biogeo.ucdavis.edu/data/gadm3.6/gadm36_levels_shp.zip | ||
# unzips downloaded zip into multiple layered shape files, which will be later on used for inflating features into database | ||
unzip gadm36_levels_shp.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/python3 | ||
|
||
try: | ||
from database_inflater import inflate_into_db | ||
from osgeo import ogr as geo | ||
from subprocess import run | ||
except ImportError as e: | ||
print('[!]Module Unavailable : {}'.format(str(e))) | ||
exit(1) | ||
|
||
|
||
def app(path='/home/anjan/Documents/my_programs/still_working/python_codes/gis_data/gadm_world_data/gadm36_{}.shp', file_id=[0, 1, 2, 3, 4, 5]): | ||
# path, path to gadm shapefiles | ||
# gadm has 6 layers, shape files hold corresponding layer number too | ||
data_set = {} | ||
for i in file_id: | ||
print('[+]Working on `{}`'.format(path.format(i))) | ||
datasource = geo.Open(path.format(i)) # datasource opened | ||
# layer fetched, only a single layer present in a shape file | ||
layer = datasource.GetLayer(0) | ||
tmp = [] | ||
for j in range(layer.GetFeatureCount()): | ||
feature = layer.GetFeature(j) # gets feature by id | ||
tmp.append([feature.items().get('GID_{}'.format(i)), | ||
feature.items().get('NAME_{}'.format(i)), | ||
feature.GetGeometryRef().ExportToWkt()]) | ||
# holds data in temp variable | ||
# data format -- [feature_id, feature_name, outline] | ||
data_set.update({i: tmp}) # pushes into dictionary | ||
print(data_set) | ||
return | ||
if(inflate_into_db('world_features', 'postgres', '@njan5m3dB', data_set)): | ||
# finally inflate into database | ||
print('[+]Done') | ||
return | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
run('clear') | ||
app() | ||
except KeyboardInterrupt: | ||
print('\n[!]Terminated') | ||
finally: | ||
exit(0) |