grass icon indicating copy to clipboard operation
grass copied to clipboard

[Bug] `v.out.ogr` export points w/ missing category twice

Open wangzcl opened this issue 1 month ago • 5 comments

Describe the bug

When a point has a category of -2147483647, it is skipped in v.out.ogr if the -c flag is not provided. Otherwise, it will be exported twice.

To reproduce

Generate 3 points. The second one has a category of -2147483647 while others are 2.

printf "P 1 1
0 0
1 1
P 1 1
1 0
1 -2147483647
P 1 1
2 0
1 3
" | v.in.ascii -n input=- output=pts format=standard --overwrite

v.info map=pts
v.category input=pts option=print

v.out.ogr input=pts output="pts.gpkg" format=GPKG --overwrite -c

This will export 4 points. If -c is not provided, only 2 points will be exported.

Expected behavior

Export points with missing cat only once.

System description

  • Operating System: Ubuntu 24.04

  • GRASS version: 8.4.1

  • details about further software components version=8.4.1 date=2025 revision=exported build_date=2025-07-21 build_platform=x86_64-pc-linux-gnu build_off_t_size=8 libgis_revision=8.4.1 libgis_date=2025-07-21T15:11:31+00:00 proj=9.4.1 gdal=3.11.3 geos=3.12.2 sqlite=3.45.1

wangzcl avatar Oct 31 '25 16:10 wangzcl

This is actually a bug in v.in.ascii because negative category values are not allowed. This is not documented in https://grass.osgeo.org/grass84/manuals/vectorintro.html but there is a admittedly hdden hint in the GRASS 8 Programmer's Manual at "Categories and Layers": Categories start with 1 (category '0' is allowed for OGR layers). Categories do not have to be continuous.

metzm avatar Nov 02 '25 18:11 metzm

Could you elaborate on how you actually got that negative value? Seems related to your other issue https://github.com/OSGeo/grass-addons/issues/1517 but perhaps more details are needed.

petrasovaa avatar Nov 03 '25 15:11 petrasovaa

Yes, I got this negative value from the output of r.stream.snap function. I'll see if I can provide a minimal reproduction of that issue.

wangzcl avatar Nov 03 '25 15:11 wangzcl

The number looks like it could be integer overflow issue.

petrasovaa avatar Nov 03 '25 15:11 petrasovaa

I provided a minimal example in https://github.com/OSGeo/grass-addons/issues/1517. It seems they somehow forgot to assign a category to some output points, which caused this unexpected behavior in v.out.ogr.

wangzcl avatar Nov 03 '25 17:11 wangzcl