[grass scripts] minor clean up
This commit is contained in:
parent
f88863e4c2
commit
640c91b369
6 changed files with 46 additions and 69 deletions
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "triangle.h"
|
||||
|
||||
|
||||
void build_segments(struct triangulateio* tri, struct Map_info* map)
|
||||
{
|
||||
plus_t node_idx, line_idx;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <grass/dbmi.h>
|
||||
#include <grass/vector.h>
|
||||
|
||||
|
||||
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 );
|
||||
|
@ -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]);
|
||||
|
||||
|
@ -132,7 +131,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (whereopt->answer!=NULL) {
|
||||
field = Vect_get_field_number( &newmap, fieldopt->answer );
|
||||
fieldinfo = Vect_get_field( &newmap, field );
|
||||
struct field_info* fieldinfo = Vect_get_field( &newmap, field );
|
||||
if (!fieldinfo) {
|
||||
G_fatal_error(_("Database connection not defined for layer <%s>"),
|
||||
fieldopt->answer);
|
||||
|
@ -140,7 +139,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
G_debug(1, "Loading categories from table <%s>", fieldinfo->table);
|
||||
|
||||
driver = db_start_driver_open_database(fieldinfo->driver, fieldinfo->database);
|
||||
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);
|
||||
|
@ -175,6 +174,7 @@ int main(int argc, char *argv[])
|
|||
if (cats != NULL) {
|
||||
G_free(cats);
|
||||
}
|
||||
|
||||
Vect_close(&newmap);
|
||||
|
||||
/* Don't forget to report to caller sucessful end of data processing :) */
|
||||
|
|
|
@ -21,10 +21,11 @@
|
|||
#include <grass/glocale.h>
|
||||
#include <grass/vector.h>
|
||||
|
||||
|
||||
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))
|
||||
|
|
|
@ -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), \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \@`
|
||||
|
|
Loading…
Reference in a new issue