[GRASS-user] exporting areas to shapefiles without filling holes

Hamish wrote:
> I've got a grass vector map containing some areas with holes.

...

> after exporting with 'v.out.ogr type=area' to a shapefile, when I load
> the shp file into QGIS 0.8.1 I see that all the holes have been filled
> in.

...

> what am I doing wrong?

Markus Metz:

Maybe use v.out.ogr -c?

yup, that's it. I'd focused on the shapefile example in the man page
and totally missed the blinking red letters at the top:

<h2>NOTES</h2>

To export areas with holes into, e.g., a Shapefile, while keeping the
holes as holes, the flag <em>-c</em> has to be used.

(example now updated in svn to use the flag)

Hamish

On Thu, Apr 9, 2009 at 10:38 AM, Hamish <hamish_b@yahoo.com> wrote:

Hamish wrote:
> I've got a grass vector map containing some areas with holes.

...

> after exporting with 'v.out.ogr type=area' to a shapefile, when I load
> the shp file into QGIS 0.8.1 I see that all the holes have been filled
> in.

...

> what am I doing wrong?

Markus Metz:

Maybe use v.out.ogr -c?

yup, that's it. I'd focused on the shapefile example in the man page
and totally missed the blinking red letters at the top:

I am also regularly missing that (and only now understand how to
solve this island problem).

Any chance to generate a warning if islands are there and -c not
given? Only then the problem + solution is obvious...

Markus

On 09/04/09 10:47, Markus Neteler wrote:

On Thu, Apr 9, 2009 at 10:38 AM, Hamish <hamish_b@yahoo.com> wrote:

Hamish wrote:

I've got a grass vector map containing some areas with holes.

...

after exporting with 'v.out.ogr type=area' to a shapefile, when I load
the shp file into QGIS 0.8.1 I see that all the holes have been filled
in.

...

what am I doing wrong?

Markus Metz:

Maybe use v.out.ogr -c?

yup, that's it. I'd focused on the shapefile example in the man page
and totally missed the blinking red letters at the top:

I am also regularly missing that (and only now understand how to
solve this island problem).

Any chance to generate a warning if islands are there and -c not
given? Only then the problem + solution is obvious...

You already have :

"%d features without category were written" (line 638 of v.out.ogr/main.c in trunk), maybe you can just add a hint there about using '-c' ?

Moritz

Markus Neteler wrote:

On Thu, Apr 9, 2009 at 10:38 AM, Hamish <hamish_b@yahoo.com> wrote:
  

Markus Metz:
    

Maybe use v.out.ogr -c?
      

yup, that's it. I'd focused on the shapefile example in the man page
and totally missed the blinking red letters at the top:
    
I am also regularly missing that (and only now understand how to
solve this island problem).

Any chance to generate a warning if islands are there and -c not
given? Only then the problem + solution is obvious...
  

Hmm, what is the most common desired situation? Exporting features also if they don't have a category or only exporting features with a category?

In the case of areas I guess that areas without centroids (typically (parts of) islands) should most commonly appear as holes and not as filled areas. I assume that points and lines usually have categories, so the -c flag should generally not make a difference. Boundaries usually don't have categories (although they can), and exporting boundaries as lines is a special case.

My question is if the behaviour of v.out.ogr could be changed for grass7 to export only features with categories by default if this is the most common situation, e.g. invert the meaning of the -c flag.

On 09/04/09 11:56, Markus Metz wrote:

Markus Neteler wrote:

On Thu, Apr 9, 2009 at 10:38 AM, Hamish <hamish_b@yahoo.com> wrote:

Markus Metz:
   

Maybe use v.out.ogr -c?
      

yup, that's it. I'd focused on the shapefile example in the man page
and totally missed the blinking red letters at the top:
    
I am also regularly missing that (and only now understand how to
solve this island problem).

Any chance to generate a warning if islands are there and -c not
given? Only then the problem + solution is obvious...
  

Hmm, what is the most common desired situation? Exporting features also if they don't have a category or only exporting features with a category?

In the case of areas I guess that areas without centroids (typically (parts of) islands) should most commonly appear as holes and not as filled areas. I assume that points and lines usually have categories, so the -c flag should generally not make a difference. Boundaries usually don't have categories (although they can), and exporting boundaries as lines is a special case.

My question is if the behaviour of v.out.ogr could be changed for grass7 to export only features with categories by default if this is the most common situation, e.g. invert the meaning of the -c flag.

+1

Moritz

Markus Metz wrote:

Markus Neteler wrote:

On Thu, Apr 9, 2009 at 10:38 AM, Hamish <hamish_b@yahoo.com> wrote:

Markus Metz:
   

Maybe use v.out.ogr -c?
      

yup, that's it. I'd focused on the shapefile example in the man page
and totally missed the blinking red letters at the top:
    
I am also regularly missing that (and only now understand how to
solve this island problem).

Any chance to generate a warning if islands are there and -c not
given? Only then the problem + solution is obvious...
  

Hmm, what is the most common desired situation? Exporting features also if they don't have a category or only exporting features with a category?

In the case of areas I guess that areas without centroids (typically (parts of) islands) should most commonly appear as holes and not as filled areas. I assume that points and lines usually have categories, so the -c flag should generally not make a difference. Boundaries usually don't have categories (although they can), and exporting boundaries as lines is a special case.

My question is if the behaviour of v.out.ogr could be changed for grass7 to export only features with categories by default if this is the most common situation, e.g. invert the meaning of the -c flag.

So what would then happen if you export a vector which includes closed boundaries which have no cat, and centroids with the cat value? (and you request type=area)??
--
Micha

Micha Silver wrote:

Markus Metz wrote:

My question is if the behaviour of v.out.ogr could be changed for grass7 to export only features with categories by default if this is the most common situation, e.g. invert the meaning of the -c flag.

So what would then happen if you export a vector which includes closed boundaries which have no cat, and centroids with the cat value? (and you request type=area)??

In this case you would get a proper, filled area, because the area has a cat. Querying the exported vector would give you all the info for that area that you would also get in grass with the original vector, no information is lost.

Boundaries in grass usually don't have cats, and if they have, they are not used for linking area attributes. In grass, only the centroid's cat is used for linking to area attributes.

Markus

On Thu, Apr 9, 2009 at 11:01 AM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 09/04/09 10:47, Markus Neteler wrote:

On Thu, Apr 9, 2009 at 10:38 AM, Hamish <hamish_b@yahoo.com> wrote:

Hamish wrote:

I've got a grass vector map containing some areas with holes.

A nice example is Italy...

GRASS 6.5.svn (LL):~ > v.out.ogr italy_country dsn=italy.shp type=area
Exporting 26 areas (may take some time)...
100%
31 features written
WARNING: 5 features without category were written

GRASS 6.5.svn (LL):~ > v.out.ogr -c italy_country
dsn=italy_with_islands.shp type=area
Exporting 26 areas (may take some time)...
100%
21 features written
WARNING: 5 features found without category were skipped

# verification
GRASS 6.5.svn (LL):~ > qgis italy.shp italy_with_islands.shp

Indeed, the -c is the correct way to export the map (too bad that the
default settings fail!).

So.... please consider following patch:

svn diff vector/v.out.ogr
Index: vector/v.out.ogr/main.c

--- vector/v.out.ogr/main.c (revision 36267)
+++ vector/v.out.ogr/main.c (working copy)
@@ -214,6 +214,9 @@
     Vect_set_open_level(2);
     Vect_open_old(&In, in_opt->answer, mapset);

+ if (Vect_get_num_islands(&In) > 0 && !cat_flag->answer)
+ G_warning(_("The map contains islands. To preserve them in the
output map, use the -c flag"));
+
     /* fetch PROJ info */
     G_get_default_window(&cellhd);
     if (cellhd.proj == PROJECTION_XY)

v.out.ogr italy_country dsn=italy.shp type=area
WARNING: The map contains islands. To preserve them, use the -c flag
Exporting 26 areas (may take some time)...
100%
31 features written
WARNING: 5 features without category were written

Makes sense?

Markus

On 10/04/09 11:56, Markus Neteler wrote:

On Thu, Apr 9, 2009 at 11:01 AM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 09/04/09 10:47, Markus Neteler wrote:

On Thu, Apr 9, 2009 at 10:38 AM, Hamish <hamish_b@yahoo.com> wrote:

Hamish wrote:

I've got a grass vector map containing some areas with holes.

A nice example is Italy...

GRASS 6.5.svn (LL):~ > v.out.ogr italy_country dsn=italy.shp type=area
Exporting 26 areas (may take some time)...
100%
31 features written
WARNING: 5 features without category were written

GRASS 6.5.svn (LL):~ > v.out.ogr -c italy_country
dsn=italy_with_islands.shp type=area
Exporting 26 areas (may take some time)...
100%
21 features written
WARNING: 5 features found without category were skipped

# verification
GRASS 6.5.svn (LL):~ > qgis italy.shp italy_with_islands.shp

Indeed, the -c is the correct way to export the map (too bad that the
default settings fail!).

So.... please consider following patch:

svn diff vector/v.out.ogr
Index: vector/v.out.ogr/main.c

--- vector/v.out.ogr/main.c (revision 36267)
+++ vector/v.out.ogr/main.c (working copy)
@@ -214,6 +214,9 @@
     Vect_set_open_level(2);
     Vect_open_old(&In, in_opt->answer, mapset);

+ if (Vect_get_num_islands(&In) > 0 && !cat_flag->answer)
+ G_warning(_("The map contains islands. To preserve them in the
output map, use the -c flag"));
+
     /* fetch PROJ info */
     G_get_default_window(&cellhd);
     if (cellhd.proj == PROJECTION_XY)

v.out.ogr italy_country dsn=italy.shp type=area
WARNING: The map contains islands. To preserve them, use the -c flag
Exporting 26 areas (may take some time)...
100%
31 features written
WARNING: 5 features without category were written

Makes sense?

To me, yes. But I think that (in addition) for grass7, we should go for Markus M's suggestion of making -c the default (i.e. inversing the meaning of the flag).

Moritz