1 | #!/bin/env python
|
---|
2 |
|
---|
3 | #
|
---|
4 | # Script to convert GADM files to UTF-8
|
---|
5 | #
|
---|
6 |
|
---|
7 | import os
|
---|
8 | import codecs
|
---|
9 |
|
---|
10 | #from osgeo import ogr
|
---|
11 |
|
---|
12 | for filePrefix in ["gadm1_lev0", "gadm1_lev1", "gadm_v1_lev2"]:
|
---|
13 |
|
---|
14 | # Download the file
|
---|
15 | #wget http://gadm.org/data/gadm_v1_lev0_shp.zip
|
---|
16 | #wget http://gadm.org/data/gadm_v1_lev1_shp.zip
|
---|
17 | #wget http://biogeo.ucdavis.edu/data/gadm/gadm_v1_lev2_shp.zip
|
---|
18 |
|
---|
19 | # Unzip it
|
---|
20 | #unzip gadm_v1_lev0_shp.zip
|
---|
21 | #unzip gadm_v1_lev1_shp.zip
|
---|
22 | #unzip gadm_v1_lev2_shp.zip
|
---|
23 |
|
---|
24 | # Use OGR to convert SHP to CSV
|
---|
25 | #ogr2ogr -f CSV CSV gadm1_lev0.shp -lco GEOMETRY=AS_WKT
|
---|
26 | #ogr2ogr -f CSV CSV gadm1_lev1.shp -lco GEOMETRY=AS_WKT
|
---|
27 | #ogr2ogr -f CSV CSV gadm_v1_lev2.shp -lco GEOMETRY=AS_WKT
|
---|
28 |
|
---|
29 | # Convert CSV to UTF-8
|
---|
30 | fileName = os.path.join("CSV", "%s.csv" % filePrefix)
|
---|
31 | fileObj = codecs.open(fileName, "r", "latin-1")
|
---|
32 | input = fileObj.read()
|
---|
33 | fileOut = codecs.open("%s_utf8.csv" % filePrefix, "w", "utf-8")
|
---|
34 | fileOut.write(input)
|
---|
35 | fileOut.close()
|
---|
36 |
|
---|
37 | #os.rmdir("CSV")
|
---|
38 |
|
---|
39 | # Import the data into PostGIS
|
---|
40 | # pgloader
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|