Saturday 18 February 2017

Rebuilding a Polygon from the points within it, in PostGIS


This question is an update on the problem formulated here.


I wanted to redefine the border of a set of polygons, in order to "smooth it". My first approach (described in the former question) was to grab the points from the border and throw them at the Concave Hull function. However, the "pixelated" look of the border was not improved, since I am keeping the same set of points to define the border.



Concave Hull of the


Thus my second approach, was to use the "raw" points within the polygon, that were used to generate it in the first place.


raw points


The idea would be to to something like this:



  • do a point in polygon query (ST_Contains) to find out the points inside each polygon.

  • send each collection of points inside a polygon to the concave hull constructor; this implies a group by query regarding the polygon geometry.


Considering the raw points table (tweets_malaga) and polygon table (exploded), I figured the query would be something like this:


SELECT ST_ConcaveHull(ST_UNION(tweets_malaga.geom),0.8) from exploded,tweets_malaga WHERE ST_Contains(exploded.geom,tweets_malaga.geom) group by exploded.geom;


However I am getting a weird error, stating:


ERROR:  Operation on mixed SRID geometries
CONTEXT: PL/pgSQL function st_concavehull(geometry,double precision,boolean) line 71 at assignment

This bugs me, as all the geometries are correctly set to 4326 :-(


srids


UPDATE:


I was able to make the above query work, setting the target_percent parameter of ST_ConcaveHull to 0.99, which is very close from having a convex hull. This parameter controls the target percent of area of convex hull the PostGIS solution will try to approach before giving up or exiting. If I set this parameter to anything less than 0.99 it will fail with the mixed SRID geometries error.


I was wondering if this had anything to do with having holes in the geometry, so I fiddled around with the allow_holes parameter of the ST_Concave without any success (in any case, the default is false).



As you can see bellow I was able to generate the concave hull, but I won't mark this question as solved as I don't understand why it is not possible to decrease the target_percent.


enter image description here




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...