1
0
Fork 0

Forgot cosmetic update ....

This commit is contained in:
Martin Spott 2010-11-22 08:00:56 -08:00
parent c352ece6f1
commit 7a47363ed2

View file

@ -1,12 +1,31 @@
#!/bin/bash #!/bin/bash
# #
# Written by Martin Spott
#
# Copyright (C) 2010 Martin Spott - Martin (at) flightgear (dot) org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
PGHOST=geoscope.optiputer.net PGHOST=geoscope.optiputer.net
PGUSER=martin PGUSER=martin
PGDATABASE=landcover PGDATABASE=landcover
PGSQL2SHPCONN="-h ${PGHOST} -u ${PGUSER} -g wkb_geometry -b -r ${PGDATABASE}" PGSQL2SHPCS="-h ${PGHOST} -u ${PGUSER} -g wkb_geometry -b -r ${PGDATABASE}"
PSQL="psql -tA -h ${PGHOST} -U ${PGUSER} -d ${PGDATABASE} -c" PSQL="psql -tA -h ${PGHOST} -U ${PGUSER} -d ${PGDATABASE} -c"
SHAPE=`basename ${1} | cut -f 1 -d \. | uniq` SHAPE=`basename ${1} | cut -f 1 -d \. | uniq`
CUTLAYER=tempcutout CUTLAYER=temphole
DIFFLAYER=tempdiff DIFFLAYER=tempdiff
LAYERPREFIX=cs_ LAYERPREFIX=cs_
LOGSCRIPT=${HOME}/cs_intersects.log LOGSCRIPT=${HOME}/cs_intersects.log
@ -79,12 +98,16 @@ CheckWithin () {
SingularizeDump () { SingularizeDump () {
if [ `${PSQL} "SELECT COUNT(*) FROM ${DIFFLAYER}"` -gt 0 ]; then if [ `${PSQL} "SELECT COUNT(*) FROM ${DIFFLAYER}"` -gt 0 ]; then
for OGC_FID in `${PSQL} "SELECT ogc_fid FROM ${DIFFLAYER} WHERE NumGeometries(wkb_geometry) IS NOT NULL"`; do for OGC_FID in `${PSQL} "SELECT ogc_fid FROM ${DIFFLAYER} WHERE NumGeometries(wkb_geometry) IS NOT NULL"`; do
${PSQL} "INSERT INTO ${DIFFLAYER} (wkb_geometry) (SELECT GeometryN(wkb_geometry, generate_series(1, NumGeometries(wkb_geometry))) AS wkb_geometry FROM ${DIFFLAYER} WHERE ogc_fid = ${OGC_FID})" ${PSQL} "INSERT INTO ${DIFFLAYER} (wkb_geometry) \
(SELECT GeometryN(wkb_geometry, generate_series(1, NumGeometries(wkb_geometry))) \
AS wkb_geometry \
FROM ${DIFFLAYER} \
WHERE ogc_fid = ${OGC_FID})"
${PSQL} "DELETE FROM ${DIFFLAYER} WHERE ogc_fid = ${OGC_FID}" ${PSQL} "DELETE FROM ${DIFFLAYER} WHERE ogc_fid = ${OGC_FID}"
done done
CPSTRING="INSERT INTO ${CSLAYER} (wkb_geometry) (SELECT wkb_geometry FROM ${DIFFLAYER})" CPSTRING="INSERT INTO ${CSLAYER} (wkb_geometry) (SELECT wkb_geometry FROM ${DIFFLAYER})"
if [ ${MODE} == "testing" ]; then if [ ${MODE} == "testing" ]; then
pgsql2shp -f ${DUMPDIR}/${CSLAYER}.shp ${PGSQL2SHPCONN} "SELECT * FROM ${DIFFLAYER}" pgsql2shp -f ${DUMPDIR}/${CSLAYER}.shp ${PGSQL2SHPCS} "SELECT * FROM ${DIFFLAYER}"
elif [ ${MODE} == "production" ]; then elif [ ${MODE} == "production" ]; then
${PSQL} "${CPSTRING}" ${PSQL} "${CPSTRING}"
fi fi
@ -97,7 +120,8 @@ CheckIntersects () {
echo "Selection requires to contain exactly one single feature - exiting !" echo "Selection requires to contain exactly one single feature - exiting !"
exit 1 exit 1
else else
for CSLAYER in `${PSQL} "SELECT f_table_name FROM geometry_columns WHERE f_table_name LIKE '${LAYERPREFIX}%' AND type LIKE 'POLYGON' ORDER BY f_table_name"`; do for CSLAYER in `${PSQL} "SELECT f_table_name FROM geometry_columns WHERE f_table_name LIKE '${LAYERPREFIX}%' \
AND type LIKE 'POLYGON' ORDER BY f_table_name"`; do
InitDiffTable InitDiffTable
for OGC_FID in `${PSQL} "SELECT ogc_fid FROM ${CSLAYER} WHERE wkb_geometry && (SELECT wkb_geometry FROM ${CUTLAYER}) ORDER BY ogc_fid"`; do for OGC_FID in `${PSQL} "SELECT ogc_fid FROM ${CSLAYER} WHERE wkb_geometry && (SELECT wkb_geometry FROM ${CUTLAYER}) ORDER BY ogc_fid"`; do
RETURN=`${PSQL} "SELECT ST_Intersects((SELECT wkb_geometry FROM ${CUTLAYER}), (SELECT wkb_geometry FROM ${CSLAYER} WHERE ogc_fid = ${OGC_FID}))"` RETURN=`${PSQL} "SELECT ST_Intersects((SELECT wkb_geometry FROM ${CUTLAYER}), (SELECT wkb_geometry FROM ${CSLAYER} WHERE ogc_fid = ${OGC_FID}))"`