Re: [GRASS-user] Merge spatially connected features

2020-03-02 Thread Johannes Radinger

Hi Micha, hi all,

sorry for my late response...however, just today I managed to try your 
approach of building polylines to connect "touching stream lines"...but...


On 24.02.20 16:48, Micha Silver wrote:


On 24/02/2020 10:45, Johannes Radinger wrote:

Hi all,
I have a large river network dataset (lines). Now I'd to assign 
unique categories to each group of connected lines that have an 
attribute in common.


For example, my rivers are categorized based on some kind of stream 
order. I want to group all rivers that belong to stream order 2 and 
are spatially connected; each group should get a unique category 
value. I thought that I could first extract all rivers with a 
particular attribute (e.g. stream order = 2) which will provide me 
some scattered pattern of lines. Then I need a spatial join tool to 
make subgroups of lines that are connected. How can I achieve the 
latter? Any idea?



Here's a procedure that might work for you. Somewhat clunky, but I 
think it gets what you want.


It's based on the v.build.polylines module to connect all touching 
stream reaches. First extract each order from the stream vector into a 
new vector. Then build polylines. Patch them all together. Now you 
have a polyline vector with a single cat value for each set of 
original stream reaches that had the same order and that were touching.


Unfortunately, the v.build.polylines tool does not work here as it does 
not connect multiple (intersecting) lines like in a river network. For 
example, I tried to build polylines from the stream network of the NC 
dataset. The suggested approach should result that each sub-network 
(i.e. river network that is not connected to another one) should get its 
own ID/cat...however, v.build.polylines results in a  stream sub-network 
that consists of multiple cats:


v.clean --overwrite input=streams@PERMANENT output=streams_break tool=break
v.build.polylines --overwrite input=streams_break@test 
output=streams_poly cats=first type=line

d.vect -c map=streams_poly

So is there any other way to join all lines that are touching...This 
would be something similar to v.dissolve but based on lines rather than 
on polygons.


Any ideas for a simple work around?

cheers,

Johannes




Finally, with v.distance you can upload that cat value to the original 
streams.



# Get a list of stream orders
ORDERS=`v.db.select -c streams group=strahler column=strahler`
echo $ORDERS
#1 2 3 4 5 6
# How many stream segments in original
v.info -t streams | grep lines
# lines=1420

# Now loop thru list of stream orders and extract stream segments for 
each order

for o in $ORDERS; do
    v.extract input=streams output=streams_${o} where="strahler=${o}"
    # Create polyline for each stream order
    # Line "connects" all touching stream segments
    v.build.polylines input=streams_${o} 
output=streams_${o}_polyline type=line cat=first

done

# Patch stream order polylines together
POLYLINES=`g.list vect pattern="streams*polyline" separator=comma`
echo $POLYLINES
v.patch input=$POLYLINES output=streams_polylines
v.info -t streams_polylines | grep lines
# lines=738

# Add a new column to the original streams for new ID value
v.db.addcolumn map=streams column="merged_id INTEGER"
# And use v.distance to update that column from cat values in 
polylines vector

v.distance from=streams to=streams_polylines upload=cat column=merged_id

HTH


Cheers,
Johannes

___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user



___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] Splitting lines by other lines that overlap

2020-03-02 Thread Markus Metz
Hi Johannes,

On Fri, Feb 28, 2020 at 4:27 PM Johannes Radinger <
johannesradin...@gmail.com> wrote:
>
> Hi all,
>
> I have two line vectors: LV1) a complete stream network LV2) sections of
the same stream network representing impoundments.
>
> LV2 is a subset of LV1 and fully spatially overlapping. However, the full
stream network consists of polylines with start/end nodes that do not
correspond to the impoundments vector:
>
> LV1 (complete network):
> +---+--+
> LV2 (subset with different start/end nodes)
>  +---+   +-+
>
> So how can I get the information of impoundments (LV2) into the attribute
table of the first line vector (LV1). A way that came into my mind but
which is somehow cumbersome:
>
> 1) Extract the start/end node coordinates each impoundment (LV2) using
v.to.db
> 2) Use these coordinates in v.edit to break the river network (LV1)
> 3) Add new categories in layer 2 of LV1 and add an attribute table
> 4) Use v.distance to query the information from LV2 and copy it to the
corresponding new reaches in LV1
> ..This is not yet tested and not the most straight forward way.
>
> All this I guess would be easier if there would be something like
v.overlay that works with two line vectors...

The only alternative I can think of is v.clean tool=break errors=nodes, but
this might not be exactly what you need: start/end nodes from LV2 might be
missing if there are matching nodes in LV1. Your approach seems to be
reasonable, even if it involves several steps.

Markus M

>
> Has anybody done similar analysis in GRASS so far?
>
> cheers,
> Johannes
>
> tart/end nodes of the
> ___
> grass-user mailing list
> grass-user@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] Can I turn off compression

2020-03-02 Thread Markus Metz
On Mon, Mar 2, 2020 at 4:58 PM Ken Mankoff  wrote:
>
> I'm not totally sure how to find the size of a GRASS raster from within
GRASS.

There is no tool in GRASS that reports the disk usage of a GRASS raster
map. r.compress only reports the change in disk usage.

> I could go to the OS to find it.

That's what I do too to find out disk usage of a GRASS raster map.

> A better report would include a scatter plot of time v. size, but I only
cared about time.
>
> Summary: Use LZ4 compression within GRASS.

Only if you don't care about disk space and if IO speed does not matter.
Particularly when sharing or archiving data, other compression methods
reducing disk space are more suitable.

Markus M
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] Can I turn off compression

2020-03-02 Thread Ken Mankoff
Hi,

Thanks for the replies. Yes I found LZ4 to be the best. In answer to Vaclav 
suggesting general interest, here are some code and results so you can test 
this on your own system which will have different disk/CPU/RAM speeds. I am 
only reporting time, not disk usage here.

I'm not totally sure how to find the size of a GRASS raster from within GRASS. 
I could go to the OS to find it. A better report would include a scatter plot 
of time v. size, but I only cared about time.

Summary: Use LZ4 compression within GRASS. For any maps that already exist, it 
isn't clear if LZ4 or uncompressed is faster. They seem about equal on my 
system using this as a test:

r.mapcalc "compressed = 42"
r.mapcalc "uncompressed = 42"
r.compress -u map=uncompressed

/usr/bin/time -f %E parallel -j 1 -N 0 r.mapcalc '"foo = compressed * 2"' ::: 
$(seq 10)
/usr/bin/time -f %E parallel -j 1 -N 0 r.mapcalc '"foo = uncompressed * 2"' ::: 
$(seq 10)


  -k.
  

grass -c EPSG:3413 ./G

g.region w=0 e=1 s=0 n=1 res=1 -pa

export GRASS_OVERWRITE=1

for C in RLE LZ4 BZIP2; do
  export GRASS_COMPRESSOR=${C}
  echo -n "${C} ": 
  /usr/bin/time -f %E parallel -j 1 -N 0 r.mapcalc '"foo = 42"' ::: $(seq 10)
done

export GRASS_COMPRESSOR=ZLIB
for ZL in $(seq -1 10); do
  export GRASS_ZLIB_LEVEL=${ZL}
  echo -n "ZLIB ${ZL} ": 
  /usr/bin/time -f %E parallel -j 1 -N 0 r.mapcalc '"foo = 42"' ::: $(seq 10)
done

RLE :0:17.39
LZ4 :0:14.51
BZIP2   :0:24.05
ZLIB -1 :0:22.49
ZLIB  0 :0:19.14
ZLIB  1 :0:20.31
ZLIB  2 :0:20.05
ZLIB  3 :0:19.87
ZLIB  4 :0:22.72
ZLIB  5 :0:22.49
ZLIB  6 :0:22.25
ZLIB  7 :0:22.32
ZLIB  8 :0:22.26
ZLIB  9 :0:22.67
ZLIB 10 :0:19.77


___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user