[GRASS-user] Map Collars (missing attachment)

some time ago, Chris wrote:
> The first issue to tackle is to remove the collars of the NOAA charts.
> I've searched the archives and there are only two dated posts and both
> recommend shapefiles. Well there are no shapefiles for the Atlantic or
> other water bodies so this method cannot work.

Hamish:

I'm not sure how that's supposed to work, but FWIW you might try the
NOAA coastline extractor or the v.in.gshhs addon module to get the
Atlantic coastline as a vector map.

> If anyone has any suggestions or ideas it would be greatly
> appreciated on how to remove map collars of NOAA charts.

the attached script is probably very far from the fastest way to do it,
but it works on the test map I tried (NOAA #12200). maybe the salmon
color needs to be a bit more fuzzy to cover different maps?
probably some maps have more than single pixel specks to be removed,
so r.neighbors window size could be upped.

(or make the resolution 2x as coarse, which would speed up processing
as well, at the cost of the edge pixels)

the idea:
1) download RNC maps from NOAA's website
2) Convert BSB format to GeoTIFF with gdalwarp
3) Import GeoTiff into GRASS
4) remove any single pixel specks from the map
5) temporarily mask out white, black, salmon colored metacontent which
   occurs in the collars
6) zoom to the extent of the color-masked map
7) save a copy of the original chart using the smaller bounds to GeoTIFF
8) ... tile GeoTIFF as needed for MapServer/WMS or GpsDrive application
9) go sailing

....

-----Inline Attachment Follows-----

hmmm, the shell script attachment seems to have been removed at some point.
Did the listserv settings change? Chris, did you get it via the cc?

cut&pasted: (hopefully yahoo's completely fubar'd mail servers of late
do not randomly line wrap it too badly)

decollar_noaa_charts.sh
-----------------------
r.in.gdal in=./BSB_ROOT/12200/12200_1_merc.tif out=noaa_12200

MAP="noaa_12200"

g.region rast="$MAP"

# check that we are dealing with a paletted map
eval `r.info -t "$MAP"`
if [ "$datatype" != "CELL" ] ; then
   echo "ERROR: only categorical maps can be processed"
fi

# find cats in map
CATS=`r.category $MAP`

# find black and white category numbers
unset BLACK WHITE SALMON
for CAT in $CATS ; do
  RULE=`r.what.color in="$MAP" value="$CAT"`
  echo "$RULE"
  COLOR=`echo "$RULE" | cut -f2 -d' '`
  if [ "$COLOR" = "0:0:0" ] ; then
     BLACK="$CAT"
  elif [ "$COLOR" = "255:255:255" ] ; then
     WHITE="$CAT"
  elif [ "$COLOR" = "219:73:150" ] ; then
     SALMON="$CAT"
  fi
done
echo "black is $BLACK, white is $WHITE, salmon is $SALMON"

REMAINING=`echo $CATS | tr ' ' '\n' | grep -vw "$BLACK\|$WHITE\|$SALMON"`

#### setup temporary file
TMP="`g.tempfile pid=$$`"
if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
    g.message -e "Unable to create temporary files"
    #exit 1
fi

echo "$BLACK = NULL" > "$TMP"
echo "$WHITE = NULL" >> "$TMP"
echo "$SALMON = NULL" >> "$TMP"
for CAT in $REMAINING ; do
   echo "$CAT = $CAT" >> "$TMP"
done

# remove stray single dots
r.neighbors in="$MAP" out="$MAP.despeckle" method=mode

# make a reclass map, setting black and white to NULL
r.reclass in="$MAP.despeckle" out="$MAP.filtered" rules="$TMP"

g.region zoom="$MAP.filtered"
r.mapcalc "$MAP.cropped = $MAP"

r.mapcalc "$MAP.cropped = $MAP.filtered"

## debug method for finding residuals
r.mapcalc "$MAP.cover = 1"
#g.region rast="$MAP"
r.mapcalc "$MAP.residual = if($MAP.cover == 1, null(), $MAP)"
r.stats -c "$MAP.residual"
## single 6,8 dot
#d.zoom to collar which should be empty
r.univar $MAP
r.out.xyz $MAP
#echo "symbol basic/star 20 -72.35262972 38.8881031 black blue" | d.graph -m
#echo "symbol basic/star 20 -74.51749113 39.27423606 black aqua" | d.graph -m

r.out.gdal in="$MAP" out="$MAP_decollared.tif" type=Byte #...

Hamish

On Wednesday 01 April 2009 18:49:49 Hamish wrote:

hmmm, the shell script attachment seems to have been removed at some point.
Did the listserv settings change? Chris, did you get it via the cc?

Got the script at this end. Given the addressing is both "to" not sure if it
came through the grass list or personal and checking both headers the
grass-user list is referenced. However since it appears that you did not get
it via the list, it must have been stripped off.

Perhaps someone else can confirm that.

--

/ch

On Thu, Apr 2, 2009 at 12:49 AM, Hamish <hamish_b@yahoo.com> wrote:
...

hmmm, the shell script attachment seems to have been removed at some point.
Did the listserv settings change?

Yes, yesterday (to convert text/html parts to plain text). I hoped
that it would do
the job correctly and not eat other attachments.
Since it doesn't, previous setting restored, no more mangling now (as before).

Markus