Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First attempt to dockerize scripts execution #13

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.vscode/
.directory
/**/
!_**/
_vendor/
!20190101/
!20190101/**/
15,852 changes: 7,926 additions & 7,926 deletions 20190101/geojson/comuni/comuni.json

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions 20190101/geojson/regioni/regioni.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file modified 20190101/geopkg/comuni/comuni.gpkg
Binary file not shown.
Binary file modified 20190101/geopkg/regioni/regioni.gpkg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified 20190101/shp/comuni/comuni.dbf
Binary file not shown.
2 changes: 1 addition & 1 deletion 20190101/shp/comuni/comuni.prj
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]
Binary file modified 20190101/shp/comuni/comuni.shp
Binary file not shown.
Binary file modified 20190101/shp/comuni/comuni.shx
Binary file not shown.
Binary file modified 20190101/shp/regioni/regioni.dbf
Binary file not shown.
2 changes: 1 addition & 1 deletion 20190101/shp/regioni/regioni.prj
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]
Binary file modified 20190101/shp/regioni/regioni.shp
Binary file not shown.
Binary file modified 20190101/shp/regioni/regioni.shx
Binary file not shown.
Binary file modified 20190101/shp/ripartizioni-geografiche/ripartizioni-geografiche.dbf
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]
Binary file modified 20190101/shp/ripartizioni-geografiche/ripartizioni-geografiche.shp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions 20190101/topojson/comuni/comuni.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions 20190101/topojson/regioni/regioni.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

File renamed without changes.
Binary file added 20190101/zip/comuni/comuni.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions 20190101/zip/comuni/comuni.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
Binary file added 20190101/zip/comuni/comuni.shp
Binary file not shown.
Binary file added 20190101/zip/comuni/comuni.shx
Binary file not shown.
File renamed without changes.
Binary file added 20190101/zip/regioni/regioni.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions 20190101/zip/regioni/regioni.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
Binary file added 20190101/zip/regioni/regioni.shp
Binary file not shown.
Binary file added 20190101/zip/regioni/regioni.shx
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["WGS_1984_UTM_Zone_32N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
Binary file not shown.
Binary file not shown.
61 changes: 61 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM python:3.7-slim AS environment

RUN apt-get update
RUN apt-get install -y \
gdal-bin \
sqlite3 \
#libsqlite3-mod-spatialite \
libsqlite3-dev \
#liblwgeom-2.5-0 \
python3-dev \
build-essential \
libxml2-dev \
libproj-dev \
libgeos-dev \
zlib1g-dev \
pkg-config \
automake \
autoconf \
autotools-dev \
#m4 \
libtool

ADD https://git.osgeo.org/gitea/rttopo/librttopo/archive/master.tar.gz /tmp
RUN tar zxf /tmp/master.tar.gz -C /tmp && rm /tmp/master.tar.gz
RUN cd /tmp/librttopo && \
./autogen.sh && \
./configure && \
make && \
make check && \
make install

ADD https://www.gaia-gis.it/gaia-sins/freexl-1.0.5.tar.gz /tmp
RUN tar zxf /tmp/freexl-1.0.5.tar.gz -C /tmp && rm /tmp/freexl-1.0.5.tar.gz
RUN cd /tmp/freexl-1.0.5 && \
./configure && \
make && \
make install

ADD http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-5.0.0-beta0.tar.gz /tmp
RUN tar zxf /tmp/libspatialite-5.0.0-beta0.tar.gz -C /tmp && rm /tmp/libspatialite-5.0.0-beta0.tar.gz
RUN cd /tmp/libspatialite-5.0.0-beta0 && \
./configure --enable-rttopo=yes --enable-gcp=yes && \
make -j8 && \
make install-strip

RUN /sbin/ldconfig -v

RUN ln -s /usr/local/lib/mod_spatialite.so.7.1.0 /usr/lib/mod_spatialite.so

FROM environment AS application

RUN mkdir -p /app
WORKDIR /app
ADD requirements.txt /app
RUN pip install -r requirements.txt
ADD main.py /app

VOLUME ["/app"]

CMD ["python", "main.py"]

50 changes: 50 additions & 0 deletions _utils/analisiGeometrie.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

set -x

DIV=$1

folder="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

cartellaDati="$folder"/../20190101

# crea cartella con l'ouput della pulizia delle geometrie
mkdir -p "$cartellaDati"/shp_clean

# crea db sqlite e poi inizializzalo come db spaziale; cancellalo se preesiste
rm -f "$cartellaDati"/analisi.sqlite
sqlite3 "$cartellaDati"/analisi.sqlite "SELECT load_extension('mod_spatialite');
SELECT InitSpatialMetadata(1);"

cartella="$cartellaDati"/shp/$DIV
mkdir -p "$cartellaDati"/shp_clean/$DIV

# analizza lo shp originale
sqlite3 "$cartellaDati"/analisi.sqlite "SELECT load_extension('mod_spatialite');
-- importa shp $DIV come tabella virtuale
CREATE VIRTUAL TABLE \"$DIV\" USING VirtualShape("$cartella/$DIV", UTF-8, 32632);
-- crea tabella con output check geometrico
create table \""$DIV"_check\" as select PKUID,GEOS_GetLastWarningMsg() msg,ST_AsText(GEOS_GetCriticalPointFromMsg()) punto from \"$DIV\" WHERE ST_IsValid(geometry) <> 1;"

# conteggia errori rilevati
errori=$(sqlite3 "$cartellaDati"/analisi.sqlite "SELECT count(*) FROM \""$DIV"_check\"")

# se ci sono errori crea nuova tabella con geometrie corrette
if [ "$errori" -gt 0 ]; then
sqlite3 "$cartellaDati"/analisi.sqlite "SELECT load_extension('mod_spatialite');
CREATE table \""$DIV"_clean\" AS SELECT * FROM \"$DIV\";
SELECT RecoverGeometryColumn('"$DIV"_clean','geometry',32632,'MULTIPOLYGON','XY');
UPDATE \""$DIV"_clean\" SET geometry = MakeValid(geometry) WHERE ST_IsValid(geometry) <> 1;"
fi

# svuota tabella output
rm -fr "$cartellaDati"/shp_clean/$DIV/*

# esporta tabella con log errori file di input
#ogr2ogr -f CSV "$cartellaDati"/shp_clean/$DIV/$DIV"_check.csv" "$cartellaDati"/analisi.sqlite $DIV"_check"

# crea shapefile con geometrie corrette
ogr2ogr "$cartellaDati"/shp_clean/$DIV/$DIV.shp "$cartellaDati"/analisi.sqlite $DIV"_clean"

# elimina db sqlite
rm -f "$cartellaDati"/analisi.sqlite
Loading