Changes between Initial Version and Version 1 of UsersWikiExamplesInsidePolygon2


Ignore:
Timestamp:
Apr 14, 2009, 9:19:30 AM (15 years ago)
Author:
pierre
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiExamplesInsidePolygon2

    v1 v1  
     1= Examples Inside Polygon 2 =
     2
     3
     4'''Temiz [http://postgis.refractions.net/pipermail/postgis-users/2007-October/017242.html asks]:'''
     5
     6How can I find the points that are in a polygon that have certain distance ( say 4.5m) to polygon's exterior ring ?
     7[[BR]]
     8
     9
     10'''Kevin [http://postgis.refractions.net/pipermail/postgis-users/2007-October/017248.html answers]:'''
     11
     12 1. Extract the exterior ring of your token polygon
     13 1. Extract all the interior rings of your polygon
     14 1. Find all interior rings that are within a certain distance from the exterior ring
     15 1. Buffered the exterior ring
     16 1. Compute the intersection of the buffered exterior ring and the interior ring that is "close"
     17
     18
     19{{{
     20-- Create a sample polygon with two interior rings.
     21 CREATE TABLE sample_poly AS
     22     SELECT 'POLYGON ((
     23         990030.8379 1002264.8323,
     24         990029.6966 1002282.0018,
     25         990036.8891 1002286.596,
     26         990043.8774 1002287.3757,
     27         990055.7296 1002285.7607,
     28         990067.8854 1002291.298,
     29         990073.974 1002293.0334,
     30         990078.2256 1002297.9519,
     31         990084.8219 1002310.654,
     32         990092.914 1002314.2926,
     33         990112.8638 1002313.4552,
     34         990117.7626 1002311.2194,
     35         990121.5065 1002305.1711,
     36         990121.2326 1002301.0389,
     37         990121.9657 1002294.9971,
     38         990118.7723 1002289.1226,
     39         990111.6309 1002285.4819,
     40         990093.4161 1002281.2291,
     41         990074.46 1002277.9317,
     42         990067.3481 1002277.3112,
     43         990063.0965 1002272.3927,
     44         990063.9371 1002265.397,
     45         990058.5601 1002259.6862,
     46         990034.5683 1002256.5587,
     47         990030.8379 1002264.8323
     48     ), (
     49         990087.7546 1002286.4867,
     50         990110.8467 1002290.5701,
     51         990115.2003 1002297.3959,
     52         990111.4054 1002302.4905,
     53         990094.3804 1002302.209,
     54         990081.0698 1002292.8592,
     55         990081.768 1002286.6585,
     56         990087.7546 1002286.4867
     57     ), (
     58         990045.9613 1002265.1177,
     59         990051.0778 1002268.9216,
     60         990051.2954 1002274.9614,
     61         990045.6124 1002282.2855,
     62         990039.5748 1002281.5037,
     63         990034.4074 1002276.7462,
     64         990034.1898 1002270.7064,
     65         990038.9005 1002265.4508,
     66         990045.9613 1002265.1177
     67     ))'::geometry AS geom;
     68
     69}}}
     70
     71[[Image(http://postgis.refractions.net/support/wiki/close_points1.png)]]
     72
     73 
     74{{{
     75-- Extract exterior ring
     76 CREATE TABLE exterior_ring AS
     77     SELECT ST_ExteriorRing(geom) AS geom
     78     FROM sample_poly;
     79
     80 -- Extract interior rings
     81 CREATE TABLE interior_rings AS
     82     SELECT ST_InteriorRingN(
     83         geom,
     84         generate_series(1, ST_NumInteriorRings(geom))) AS geom
     85     FROM sample_poly;
     86
     87}}}
     88
     89[[Image(http://postgis.refractions.net/support/wiki/close_points2.png rings)]]
     90
     91 
     92{{{
     93-- Identify intersection points of buffered ext ring and interior rings.
     94 SELECT ST_Intersection(e.buff_geom, i.geom)
     95 FROM
     96    (SELECT geom,
     97            ST_Buffer(geom, 4.5) AS buff_geom
     98     FROM exterior_ring
     99     ) AS e,
     100    interior_rings i
     101 WHERE ST_DWithin(e.geom, i.geom, 4.5);
     102
     103}}}
     104
     105[[Image(http://postgis.refractions.net/support/wiki/close_points3.png close points)]]