Skip to content

Commit b1f9b3c

Browse files
committed
use os.remove. add staging recipes for countries and districts
1 parent b7b4a88 commit b1f9b3c

File tree

5 files changed

+65
-9
lines changed

5 files changed

+65
-9
lines changed

api/management/commands/update-mapbox-tilesets.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ def handle(self, *args, **options):
7777
def update_countries(self, staging):
7878
try:
7979
print('Exporting countries...')
80-
subprocess.check_call(['touch', '/tmp/countries.geojson'])
81-
subprocess.check_call(['rm', '/tmp/countries.geojson'])
80+
81+
try:
82+
os.remove(f'/tmp/countries.geojson')
83+
except FileNotFoundError as e:
84+
pass
85+
8286
subprocess.check_call(['ogr2ogr', '-f', 'GeoJSON', '/tmp/countries.geojson', self.connection_string, '-sql', 'select cd.country_id, cd.geom, c.name, c.name_es, c.name_fr, c.name_ar, c.iso, c.region_id, c.iso3, c.independent, c.is_deprecated, c.disputed, c.fdrs, c.record_type from api_countrygeoms cd, api_country c where cd.country_id = c.id and c.record_type=1' ])
8387
print('Countries written to /tmp/countries.geojson')
8488
except Exception as e:
@@ -87,9 +91,13 @@ def update_countries(self, staging):
8791

8892
try:
8993
print('Exporting country centroids...')
90-
subprocess.check_call(['touch', '/tmp/country-centroids.geojson'])
91-
subprocess.check_call(['rm', '/tmp/country-centroids.geojson'])
92-
subprocess.check_call(['ogr2ogr', '-lco', 'COORDINATE_PRECISION=4', '-f', 'GeoJSON', '/tmp/country-centroids.geojson', connection_string, '-sql', 'select id as country_id, name_en as name, name_ar, name_es, name_fr, independent, disputed, is_deprecated, iso, iso3, record_type, fdrs, region_id, centroid from api_country where centroid is not null'])
94+
95+
try:
96+
os.remove(f'/tmp/country-centroids.geojson')
97+
except FileNotFoundError as e:
98+
pass
99+
100+
subprocess.check_call(['ogr2ogr', '-lco', 'COORDINATE_PRECISION=4', '-f', 'GeoJSON', '/tmp/country-centroids.geojson', self.connection_string, '-sql', 'select id as country_id, name_en as name, name_ar, name_es, name_fr, independent, disputed, is_deprecated, iso, iso3, record_type, fdrs, region_id, centroid from api_country where centroid is not null'])
93101
except Exception as e:
94102
print('Failed to export country centroids', e)
95103
raise
@@ -132,8 +140,12 @@ def update_countries(self, staging):
132140
def update_districts(self, staging):
133141
try:
134142
print('Exporting districts...')
135-
subprocess.check_call(['touch', '/tmp/districts.geojson'])
136-
subprocess.check_call(['rm', '/tmp/districts.geojson'])
143+
144+
try:
145+
os.remove(f'/tmp/distrcits.geojson')
146+
except FileNotFoundError as e:
147+
pass
148+
137149
# FIXME eventually should be name_en, name_es etc.
138150
subprocess.check_call(['ogr2ogr', '-lco', 'COORDINATE_PRECISION=5', '-f', 'GeoJSON', '/tmp/districts.geojson', self.connection_string, '-sql', 'select cd.district_id, cd.geom, c.name, c.code, c.country_id, c.is_enclave, c.is_deprecated, country.iso as country_iso, country.iso3 as country_iso3, country.name as country_name, country.name_es as country_name_es, country.name_fr as country_name_fr, country.name_ar as country_name_ar from api_districtgeoms cd, api_district c, api_country country where cd.district_id = c.id and cd.geom is not null and country.id=c.country_id' ])
139151
print('Districts written to /tmp/districts.geojson')
@@ -143,8 +155,12 @@ def update_districts(self, staging):
143155

144156
try:
145157
print('Exporting district centroids...')
146-
subprocess.check_call(['touch', '/tmp/district-centroids.geojson'])
147-
subprocess.check_call(['rm', '/tmp/district-centroids.geojson'])
158+
159+
try:
160+
os.remove(f'/tmp/district-centroids.geojson')
161+
except FileNotFoundError as e:
162+
pass
163+
148164
# FIXME eventually should be name_en, name_es etc.
149165
subprocess.check_call(['ogr2ogr', '-lco', 'COORDINATE_PRECISION=4', '-f', 'GeoJSON', '/tmp/district-centroids.geojson', self.connection_string, '-sql', 'select d.id as district_id, d.country_id as country_id, d.name, d.code, d.is_deprecated, d.is_enclave, c.iso as country_iso, c.iso3 as country_iso3, c.name as country_name, c.name_es as country_name_es, c.name_fr as country_name_fr, c.name_ar as country_name_ar, d.centroid from api_district d join api_country c on d.country_id=c.id where d.centroid is not null'])
150166
except Exception as e:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": 1,
3+
"layers": {
4+
"go-countries-staging": {
5+
"source": "mapbox://tileset-source/go-ifrc/go-countries-src-staging",
6+
"minzoom": 0,
7+
"maxzoom": 10
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": 1,
3+
"layers": {
4+
"go-country-centroids-staging": {
5+
"source": "mapbox://tileset-source/go-ifrc/go-country-centroids-staging",
6+
"minzoom": 0,
7+
"maxzoom": 10
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": 1,
3+
"layers": {
4+
"go-district-centroids-staging": {
5+
"source": "mapbox://tileset-source/go-ifrc/go-district-centroids-staging",
6+
"minzoom": 3,
7+
"maxzoom": 10
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": 1,
3+
"layers": {
4+
"go-districts-staging": {
5+
"source": "mapbox://tileset-source/go-ifrc/go-districts-src-staging",
6+
"minzoom": 3,
7+
"maxzoom": 10
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)