[postgis-users] First attempt to use raster - need help

Regina Obe lr at pcorp.us
Sat Jan 13 11:08:00 PST 2018


Steve,

You are correct all the functions see each tile individually.

What I usually do is union the results by file name.  As I recall if you loaded with -F the file name is output in field called filename

So something like:

SELECT  filename, val, ST_Union(geom) as geom
FROM  (
select filename, dp.*
from "12322240_lines", lateral st_dumpaspolygons(img, 1, true) as dp
) as foo
GROUP BY filename, val;

Should give you a polygon/multipolygon for each file/ink color

After you do that you will have polygons.  To convert to linkes, yes Skeletonize would be the next step.
I haven't tried myself, but if you have postgis_sfcgal extension installed, using ST_StraightSkeleton might do the trick

https://postgis.net/docs/manual-2.4/ST_StraightSkeleton.html

Hope that helps,
Regina


-----Original Message-----
From: postgis-users [mailto:postgis-users-bounces at lists.osgeo.org] On Behalf Of Stephen Woodbridge
Sent: Saturday, January 13, 2018 12:13 PM
To: PostGIS Users Discussion <postgis-users at lists.osgeo.org>
Subject: [postgis-users] First attempt to use raster - need help

Hi all,

Sorry, if you get this twice, I sent this to the gdal list by mistake.

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

_______________________________________________
postgis-users mailing list
postgis-users at lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/postgis-users



More information about the postgis-users mailing list