[gdal-dev] First attempt to use raster - need help

Vincent Mora vincent.mora at oslandia.com
Tue Jan 16 04:06:58 PST 2018


Hi Steve,

I think I'd try to first transform rasters linework into vector linework
with gdal_contour (1 level) then import the shapefile into postgis.

I'd try to snap to grid, remove duplicated points, collect and unary
union, and lastly simplify and polygonize.

If you have sfcgal installed, you can also try to polygonize the vector
linework (polygons need to be closes, by easily achieved by adding a 1
pixel background-colored border to the starting image) and use
straight-skeleton or approx medial axis on that.

Good luck,

V.



Le 13/01/2018 à 18:01, Stephen Woodbridge a écrit :
> Hi all,
>
> I'm trying to use the raster functions for the first time. I have a
> simple black and white image with some polygons drawn on it. and I
> want to extract the polygons as geometry.
>
> $ gdalinfo -hist 12322240_lines.png
> Driver: PNG/Portable Network Graphics
> Files: 12322240_lines.png
>        12322240_lines.png.aux.xml
> Size is 600, 800
> Coordinate System is `'
> Corner Coordinates:
> Upper Left  (    0.0,    0.0)
> Lower Left  (    0.0,  800.0)
> Upper Right (  600.0,    0.0)
> Lower Right (  600.0,  800.0)
> Center      (  300.0,  400.0)
> Band 1 Block=600x1 Type=Byte, ColorInterp=Gray
>   256 buckets from -0.5 to 255.5:
>   474137 5863 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>   Image Structure Metadata:
>     NBITS=1
>
> the background is the 474137bucket and the line work is the 5863 bucket.
>
> $ raster2pgsql -t auto -P -c -f img -F -n file -I -M *.png |
> /usr/lib/postgresql/9.5/bin/psql -U postgres -h localhost -p 5435
> test_sketch
>
> I'm loading 2 PNG images in this example, about ultimately I will have
> 100-1000s of images to process and extract the line work.
>
> SELECT (md).*, (bmd).*
>  FROM (SELECT ST_Metadata(img) AS md,
>               ST_BandMetadata(img) AS bmd
>        FROM "12322240_lines" LIMIT 1
>       ) foo;
>
> -- 0;0;30;32;1;-1;0;0;0;1;"8BUI";;f;""
>
> select rid, val, st_astext(geom) as wkt
> from (
> select rid, dp.*
> from "12322240_lines", lateral st_dumpaspolygons(img, 1, true) as dp
> ) as foo;
>
> This generates 1349 rows. So it appears to be processing these an a
> tile by tile basis not on the whole image. How do I get the polygons
> that are represented by the sketch. Assuming that the sketch lines are
> 1 or 2 pixels wide, I presume that I would get the polygon around
> those pixels. Do I need to then skeletonize that to get the original
> lines?
>
> select * from "12322240_lines";
>
> generates 100 rows.
>
>
> Any thoughts on how to best approach this would be appreciated.
>
> Thanks,
>
>   -Steve
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev




More information about the gdal-dev mailing list