fix clipping issue by using ogr2ogr instead of shp2pgsql

pull/73/merge
Etienne Trimaille 2018-09-01 14:13:24 -04:00
rodzic 0f74c17265
commit 0b1cdbafc8
5 zmienionych plików z 17 dodań i 15 usunięć

Wyświetl plik

@ -52,10 +52,10 @@ kill:
@echo "------------------------------------------------------------------"
@docker-compose -f $(COMPOSE_FILE) -p $(PROJECT_ID) kill
rm: kill
rm: kill rm-volumes
@echo
@echo "------------------------------------------------------------------"
@echo "Removing production instance!!! "
@echo "Removing production instance and all volumes!!! "
@echo "------------------------------------------------------------------"
@docker-compose -f $(COMPOSE_FILE) -p $(PROJECT_ID) rm
@ -64,7 +64,7 @@ rm-volumes:
@echo "------------------------------------------------------------------"
@echo "Removing all volumes!!!! "
@echo "------------------------------------------------------------------"
@docker volume rm docker-osm_osm-postgis-data docker-osm_import_queue docker-osm_import_done docker-osm_cache
@docker volume rm $(PROJECT_ID)_osm-postgis-data $(PROJECT_ID)_import_queue $(PROJECT_ID)_import_done $(PROJECT_ID)_cache
logs:
@echo
@ -89,14 +89,14 @@ live_logs:
import_clip:
@echo
@echo "------------------------------------------------------------------"
@echo "Importing clip shapefile"
@echo "Importing clip shapefile into the database"
@echo "------------------------------------------------------------------"
@docker exec -t -i $(PROJECT_ID)_db /usr/bin/shp2pgsql -c -I -D -s 4326 /home/settings/clip/clip.shp | docker exec -i $(PROJECT_ID)_db su - postgres -c "psql gis"
@docker exec -t -i $(PROJECT_ID)_imposm /usr/bin/ogr2ogr -lco GEOMETRY_NAME=geom -f PostgreSQL PG:"host=db user=docker password=docker dbname=gis" /home/settings/clip/clip.shp
remove_clip:
@echo
@echo "------------------------------------------------------------------"
@echo "Removing clip shapefile"
@echo "Removing clip shapefile from the database"
@echo "------------------------------------------------------------------"
@docker exec -t -i $(PROJECT_ID)_db /bin/su - postgres -c "psql gis -c 'DROP TABLE IF EXISTS clip;'"

Wyświetl plik

@ -4,6 +4,7 @@ MAINTAINER Etienne Trimaille <etienne.trimaille@gmail.com>
RUN apt update && apt install -y python3-pip \
libprotobuf-dev libleveldb-dev libgeos-dev \
libpq-dev python3-dev postgresql-client-9.6 python-setuptools \
gdal-bin \
--no-install-recommends
RUN ln -s /usr/lib/libgeos_c.so /usr/lib/libgeos.so

Wyświetl plik

@ -239,16 +239,16 @@ class Importer(object):
The user must import the clip shapefile to the database!
"""
self.info('Import clip function.')
self.info('Import clip SQL function.')
command = ['psql']
command += ['-h', self.default['POSTGRES_HOST']]
command += ['-U', self.default['POSTGRES_USER']]
command += ['-d', self.default['POSTGRES_DBNAME']]
command += ['-f', self.clip_sql_file]
call(command)
self.info('!! Be sure to run \'make import_clip\' !!')
self.info('!! Be sure to run \'make import_clip\' to import the shapefile into the DB !!')
def clip(self):
def perform_clip_in_db(self):
"""Perform clipping if the clip table is here."""
if self.count_table('clip') == 1:
self.info('Clipping')
@ -313,7 +313,7 @@ class Importer(object):
if self.clip_shape_file:
self._import_clip_function()
self.clip()
self.perform_clip_in_db()
if self.qgis_style:
self.import_qgis_styles()
@ -348,7 +348,7 @@ class Importer(object):
self.update_timestamp(database_timestamp)
if self.clip_shape_file:
self.clip()
self.perform_clip_in_db()
self.info('Import diff successful : %s' % diff)
else:

Wyświetl plik

@ -76,9 +76,10 @@ you don't set a clipping area, you will end with data from all over the world.
You can put a shapefile in the clip folder. This shapefile will be
used for clipping every features after the import.
This file has to be named 'clip.shp'. When the database container is
running, import the shapefile in the database using the command :
'make import_clip'.
This file has to be named 'clip.shp' and in the CRS you are using in the database (4326 by default).
When the database container is running, import the shapefile in the database using the command :
`make import_clip`.
You can remove the clip file : `make remove_clip`.

Wyświetl plik

@ -12,7 +12,7 @@ BEGIN
SELECT DISTINCT osm_id
FROM ' || quote_ident(osm_table.table_name) || '
LEFT JOIN clip ON ST_Intersects(geometry, geom)
WHERE clip.gid IS NULL)
WHERE clip.id IS NULL)
;';
END LOOP;
END;