From 640c91b3690b8dceac1cefe1915f4060532563ec Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Thu, 31 Jan 2019 16:54:37 -0600 Subject: [PATCH] [grass scripts] minor clean up --- gismodules/v.contri/main.c | 1 + gismodules/v.flatten/main.c | 78 ++++++++++++++++----------------- gismodules/v.out.btg/main.c | 5 ++- gisscripts/IntersectsRemoval.sh | 7 --- gisscripts/grassVMap.sh | 21 ++------- gisscripts/grassVMap0convert.sh | 3 -- 6 files changed, 46 insertions(+), 69 deletions(-) diff --git a/gismodules/v.contri/main.c b/gismodules/v.contri/main.c index 0e0f5330..ed02edd9 100644 --- a/gismodules/v.contri/main.c +++ b/gismodules/v.contri/main.c @@ -33,6 +33,7 @@ #include "triangle.h" + void build_segments(struct triangulateio* tri, struct Map_info* map) { plus_t node_idx, line_idx; diff --git a/gismodules/v.flatten/main.c b/gismodules/v.flatten/main.c index 954d08d6..9effcb5d 100644 --- a/gismodules/v.flatten/main.c +++ b/gismodules/v.flatten/main.c @@ -24,7 +24,8 @@ #include #include -void apply_setz_operator( struct Map_info* map, double z, int* cats, int ncats, int layer) + +void apply_setz_operator(struct Map_info* map, double z, int* cats, int ncats, int layer) { const plus_t area_count = Vect_get_num_areas( map ); plus_t area_idx; @@ -42,7 +43,7 @@ void apply_setz_operator( struct Map_info* map, double z, int* cats, int ncats, } } -void apply_mean_operator( struct Map_info* map, int* cats, int ncats, int layer ) +void apply_mean_operator(struct Map_info* map, int* cats, int ncats, int layer) { if (ncats > 0) { /* We have to greedily collect adjacent selected areas */ @@ -53,7 +54,7 @@ void apply_mean_operator( struct Map_info* map, int* cats, int ncats, int layer } } -void apply_slope_operator( struct Map_info* map, double slope, int* cats, int ncats, int layer) +void apply_slope_operator(struct Map_info* map, double slope, int* cats, int ncats, int layer) { if (ncats > 0) { /* We apply slope to individual areas */ @@ -73,9 +74,7 @@ int main(int argc, char *argv[]) struct Option *fieldopt; int field; struct Map_info oldmap, newmap; - struct field_info* fieldinfo; - dbDriver* driver; - int i, ncats, *cats; + int ncats, *cats; G_gisinit(argv[0]); @@ -131,36 +130,36 @@ int main(int argc, char *argv[]) Vect_close(&oldmap); if (whereopt->answer!=NULL) { - field = Vect_get_field_number( &newmap, fieldopt->answer ); - fieldinfo = Vect_get_field( &newmap, field ); - if (!fieldinfo) { - G_fatal_error(_("Database connection not defined for layer <%s>"), - fieldopt->answer); - } - - G_debug(1, "Loading categories from table <%s>", fieldinfo->table); - - driver = db_start_driver_open_database(fieldinfo->driver, fieldinfo->database); - if (driver == NULL) { - G_fatal_error(_("Unable to open database <%s> by driver <%s>"), - fieldinfo->database, fieldinfo->driver); - } - - ncats = db_select_int(driver, fieldinfo->table, fieldinfo->key, whereopt->answer, - &cats); - if (ncats == -1) { - G_fatal_error(_("Unable select records from table <%s>"), fieldinfo->table); - } - G_message(_("%d categories loaded from table <%s>"), ncats, - fieldinfo->table); - - db_close_database(driver); - db_shutdown_driver(driver); - } else { - field = -1; - cats = NULL; - ncats = -1; - } + field = Vect_get_field_number( &newmap, fieldopt->answer ); + struct field_info* fieldinfo = Vect_get_field( &newmap, field ); + if (!fieldinfo) { + G_fatal_error(_("Database connection not defined for layer <%s>"), + fieldopt->answer); + } + + G_debug(1, "Loading categories from table <%s>", fieldinfo->table); + + dbDriver* driver = db_start_driver_open_database(fieldinfo->driver, fieldinfo->database); + if (driver == NULL) { + G_fatal_error(_("Unable to open database <%s> by driver <%s>"), + fieldinfo->database, fieldinfo->driver); + } + + ncats = db_select_int(driver, fieldinfo->table, fieldinfo->key, whereopt->answer, + &cats); + if (ncats == -1) { + G_fatal_error(_("Unable select records from table <%s>"), fieldinfo->table); + } + G_message(_("%d categories loaded from table <%s>"), ncats, + fieldinfo->table); + + db_close_database(driver); + db_shutdown_driver(driver); + } else { + field = -1; + cats = NULL; + ncats = -1; + } if (!strcmp(operator->answer, "setz")) { apply_setz_operator( &newmap, atof(value->answer), cats, ncats, field ); @@ -172,9 +171,10 @@ int main(int argc, char *argv[]) Vect_build(&newmap); - if (cats != NULL) { - G_free(cats); - } + if (cats != NULL) { + G_free(cats); + } + Vect_close(&newmap); /* Don't forget to report to caller sucessful end of data processing :) */ diff --git a/gismodules/v.out.btg/main.c b/gismodules/v.out.btg/main.c index 54e24b4b..923ed106 100644 --- a/gismodules/v.out.btg/main.c +++ b/gismodules/v.out.btg/main.c @@ -21,10 +21,11 @@ #include #include + int main(int argc, char *argv[]) { struct GModule *module; /* GRASS module for parsing arguments */ - struct Option *old, *new; + struct Option *old; struct Map_info oldmap; G_gisinit(argv[0]); @@ -36,7 +37,7 @@ int main(int argc, char *argv[]) /* Define the different options as defined in gis.h */ old = G_define_standard_option(G_OPT_V_INPUT); - new = G_define_standard_option(G_OPT_F_OUTPUT); + G_define_standard_option(G_OPT_F_OUTPUT); /* options and flags parser */ if (G_parser(argc, argv)) diff --git a/gisscripts/IntersectsRemoval.sh b/gisscripts/IntersectsRemoval.sh index d5ef5f8d..f24e2f81 100755 --- a/gisscripts/IntersectsRemoval.sh +++ b/gisscripts/IntersectsRemoval.sh @@ -39,13 +39,6 @@ MODE="testing" # production, testing InitCutoutTable () { ${PSQL} "DROP TABLE ${CUTLAYER}" -# ${PSQL} "CREATE TABLE ${CUTLAYER} (ogc_fid serial NOT NULL, \ -# wkb_geometry geometry, \ -# CONSTRAINT enforce_dims_wkb_geometry CHECK (ST_NDims(wkb_geometry) = 2), \ -# CONSTRAINT enforce_geotype_wkb_geometry CHECK ((ST_GeometryType(wkb_geometry) = 'ST_Polygon'::text) \ -# OR (ST_GeometryType(wkb_geometry) = 'ST_MultiPolygon'::text)), \ -# CONSTRAINT enforce_srid_wkb_geometry CHECK (ST_SRID(wkb_geometry) = 4326) \ -# )" ${PSQL} "CREATE TABLE ${CUTLAYER} (ogc_fid serial NOT NULL, \ wkb_geometry geometry, \ CONSTRAINT enforce_dims_wkb_geometry CHECK (ST_NDims(wkb_geometry) = 2), \ diff --git a/gisscripts/grassVMap.sh b/gisscripts/grassVMap.sh index 89333a3b..9e7d42a5 100755 --- a/gisscripts/grassVMap.sh +++ b/gisscripts/grassVMap.sh @@ -25,10 +25,11 @@ date DUMPDIR=${HOME}/shp mkdir -p ${DUMPDIR} RUNDIR=`pwd` + cd `dirname ${0}` && export BASEDIR=`pwd` + cd ${RUNDIR} CALLNAME=`basename ${0}` -# MAPPINGFILE=${BASEDIR}/CORINEtoCS.txt if [ ${CALLNAME} = "grassVMap.sh" ]; then @@ -50,33 +51,24 @@ elif [ ${CALLNAME} = "grassCLC06.sh" ]; then else SRCID=0 fi + PREFIX=${TYPE}${YEAR} -#PREFIX=nl -#PREFIX=clc${YEAR}_nl CLEANMAP=cleanmap if [ ${TYPE} = "v0" ]; then SRCKBS=nad83 - #SNAP=0.00001 SNAP=0.000001 - #MIN_AREA1=1 MIN_AREA1=0.0000001 MIN_AREA=100 - #MIN_AREA=0.000000001 elif [ ${TYPE} = "cs" ]; then SRCKBS=wgs84 SNAP=0.000001 - #MIN_AREA1=1 MIN_AREA1=0.0000001 MIN_AREA=1 elif [ ${TYPE} = "clc" ]; then SRCKBS=laea SNAP=0.01 - #SNAP=0.001 - #SNAP=0.0001 - #SNAP=0.000001 MIN_AREA=1 - #MIN_AREA=0.000000001 fi ######################################################################## @@ -148,7 +140,6 @@ fn_importVMap() { LAYER=`basename ${SHAPEFILE} | cut -f 1 -d \.` MAP=`echo ${LAYER} | sed -e 's/-/_/g'` g.remove vect=${MAP} -# v.in.ogr dsn="${LOADDIR}" layer=${LAYER} output=${MAP} snap=${SNAP} --verbose v.in.ogr dsn="${LOADDIR}" layer=${LAYER} output=${MAP} --verbose done } @@ -238,11 +229,9 @@ fn_split() { v.extract -t input=${LAYER} type=area output=${PREFIX}_mixedcrop_${ZONE} where="f_code NOT LIKE 'BH135' and veg = 0" v.extract -t input=${LAYER} type=area output=${PREFIX}_drycrop_${ZONE} where="f_code NOT LIKE 'BH135' and veg = 1" v.extract -t input=${LAYER} type=area output=${PREFIX}_irrcrop_${ZONE} where="f_code NOT LIKE 'BH135' and veg > 1" -# v.extract -t input=${LAYER} type=area output=${PREFIX}_rice_${ZONE} where="f_code LIKE 'BH135'" ;; "grassa@veg(*)_area") v.extract -t input=${LAYER} type=area output=${PREFIX}_grassland_${ZONE} where="f_code LIKE 'EB010'" -# v.extract -t input=${LAYER} type=area output=${PREFIX}_bamboo_${ZONE} where="f_code LIKE 'EC010'" v.extract -t input=${LAYER} type=area output=${PREFIX}_scrub_${ZONE} where="f_code NOT LIKE 'EB010' AND f_code NOT LIKE 'EC010'" ;; "oasisa@veg(*)_area") @@ -257,7 +246,6 @@ fn_split() { v.extract -t input=${LAYER} type=area output=${PREFIX}_marsh_${ZONE} where="f_code NOT LIKE 'BH015'" ;; "treesa@veg(*)_area") -# v.extract -t input=${LAYER} type=area output=${PREFIX}_mangrove_${ZONE} where="veg = 19" v.extract -t input=${LAYER} type=area output=${PREFIX}_deciduousforest_${ZONE} where="veg = 24" v.extract -t input=${LAYER} type=area output=${PREFIX}_evergreenforest_${ZONE} where="veg = 25" v.extract -t input=${LAYER} type=area output=${PREFIX}_mixedforest_${ZONE} where="veg != 19 AND veg != 24 AND veg != 25" @@ -292,7 +280,6 @@ fn_reclass() { done g.remove vect=${OUTPUT}_patched v.patch input=`g.mlist type=vect pattern="${OUTPUT}_[a-z][a-z][a-z]_lcclass" separator=,` output=${OUTPUT}_patched -# v.patch input=`g.mlist type=vect pattern="${OUTPUT}_[a-z][a-z][a-z]_lcclass" separator=,` output=${INTMAP} g.remove vect=${OUTPUT}_bpol,${OUTPUT}_snap,${OUTPUT}_split,${OUTPUT}_rmsa,${OUTPUT}_rmdangle,${OUTPUT}_rmarea,${OUTPUT}_prune v.clean input=${OUTPUT}_patched output=${OUTPUT}_bpol -c tool=bpol type=boundary --verbose @@ -451,7 +438,6 @@ fn_export() { # SELECTION=`v.category input=${CLEANMAP} type=centroid option=print | sort -n | uniq` for CATEGORY in ${SELECTION}; do -# LAYER=${PREFIX}_${CATEGORY} LAYER=`grep \^${CATEGORY} ${MAPPINGFILE} | awk '{print $2}' | sed -e "s/^cs_/${PREFIX}_/g"` g.remove vect=${LAYER} v.extract cats=${CATEGORY} input=${CLEANMAP} output=${LAYER} type=area @@ -461,7 +447,6 @@ fn_export() { g.rename vect=${LAYER},${NEWLAYER} LAYER=${NEWLAYER} fi -# v.out.ogr input=${LAYER} type=area dsn=${DUMPDIR}/${PREFIX}_c${CATEGORY}.shp # For CLC v.out.ogr input=${LAYER} type=area dsn=${DUMPDIR}/${LAYER}.shp # For VMap0/CS fn_topostgis ${LAYER} done diff --git a/gisscripts/grassVMap0convert.sh b/gisscripts/grassVMap0convert.sh index 3cf336cf..7d4b8660 100755 --- a/gisscripts/grassVMap0convert.sh +++ b/gisscripts/grassVMap0convert.sh @@ -28,8 +28,6 @@ mkdir -p ${DUMPDIR} export LD_LIBRARY_PATH=/opt/GRASS.32/lib OGR2OGR=/opt/GRASS.32/bin/ogr2ogr OGRINFO=/opt/GRASS.32/bin/ogrinfo -#OGR2OGR=/usr/local/bin/ogr2ogr -#OGRINFO=/usr/local/bin/ogrinfo AREAS="v0eur_5/vmaplv0/eurnasia v0noa_5/vmaplv0/noamer v0sas_5/vmaplv0/sasaus v0soa_5/vmaplv0/soamafr" @@ -46,7 +44,6 @@ GetFeatureNames () { ConvertToSHapefiles () { for VMAP_URL in ${AREAS}; do ZONE=`echo ${VMAP_URL} | cut -f 1 -d \/ | sed -e 's/^v0//g' -e 's/_5\$//g'` -# for FEATURE in `GetFeatureNames`; do for FEATURE in `${OGRINFO} gltp:/vrf/home/martin/live/vmap0/${VMAP_URL} 2>&1 | egrep \^"[0-9].*@" | awk '{print $2}' | sort | uniq`; do CATEGORY=`echo ${FEATURE} | cut -f 1 -d \@` DIR=`echo ${FEATURE} | cut -f 1 -d \( | cut -f 2 -d \@`