-
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
1fc23ca
commit 7eeb295
Showing
1 changed file
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/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='/path-to-file/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 | ||
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) | ||
data_set = {} | ||
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 | ||
if(inflate_into_db('world_features', 'username', 'password', data_set)): | ||
# finally inflate into database | ||
print('[+]Success') | ||
return | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
run('clear') | ||
app() | ||
except KeyboardInterrupt: | ||
print('\n[!]Terminated') | ||
finally: | ||
exit(0) |