[postgis-users] Cut a hole in a line layer (opposite of a cookiecutter)??

Martin Davis mbdavis at refractions.net
Mon Jun 4 10:07:52 PDT 2007


The documentation for the function syntax is here:

http://postgis.refractions.net/docs/ch06.html#id2527029

Basically difference(A, B) subtracts a geometry B from a geometry A, and 
returns all the parts (point-sets) of A which are not covered (occur in) 
B.  So in your case, you want to code up difference(line, polygon), 
which will return a MultiLineString which contains all the bits of line 
which aren't covered by the polygon.

Matt Doughty wrote:
> The 'Difference(geometry,geometry)' tool? I've had a look at that but
> could quite understand how it works and what the syntax was, the PostGIS
> manual was particularly unhelpful. 
>
> I'll have another look the how I can take the difference, but in the
> meantime, if you've got any pointers...
>
> ... Matt
>  
>  
> Matt Doughty
>  
> GEOGRAMA S.L.
> Tel.:  +34 945 13 13 72    652 77 14 15
> Fax: +34 945 23 03 40 
> www.geograma.com
>  
>  
>
> -----Mensaje original-----
> De: postgis-users-bounces at postgis.refractions.net
> [mailto:postgis-users-bounces at postgis.refractions.net] En nombre de
> Martin Davis
> Enviado el: lunes, 04 de junio de 2007 17:53
> Para: PostGIS Users Discussion
> Asunto: Re: [postgis-users] Cut a hole in a line layer (opposite of a
> cookiecutter)??
>
> You could form the union of the "mask" polygons and then use the 
> difference function to obtain the portion of each line which lies 
> outside them.
>
> This assumes of course that your polygon layer isn't too big. If it is 
> very big, you may need to use the approach of taking the difference of 
> every line from the union of the polys which interact with that line. 
> This might be slow, however.
>
> Matt Doughty wrote:
>   
>> Hi,
>>
>> I've got a new problem... how in PostGIS could I perform the opposite
>>     
> of 
>   
>> a cookie cutting operation? Better said, use a polygon layer to cut a 
>> hole in a line layer thereby keeping the lines from outside the 
>> polygons but not those inside. I've been trying with a cooking cutting
>>     
>
>   
>> script (see below) by placing NOT before the operators but without 
>> much luck.
>>
>> SELECT
>>
>> cookie.gid,
>>
>> INTERSECTION(cookie.the_geom, cutter.the_geom) AS the_geom
>>
>> INTO
>>
>> curvas_isla_not_02
>>
>> FROM
>>
>> roads AS cookie,
>>
>> urban_areas AS cutter
>>
>> WHERE
>>
>> cookie.the_geom && cutter.the_geom
>>
>> AND
>>
>> INTERSECTS(cookie.the_geom, cutter.the_geom)
>>
>> I've also tried to use the results from the cookie cutter script to 
>> select those lines that don't coincide with those from the cookie (see
>>     
>
>   
>> below), but also without any luck.
>>
>> SELECT
>>
>> roads.gid,
>>
>> roads.the_geom
>>
>> INTO
>>
>> roads_not_urban
>>
>> FROM
>>
>> roads,
>>
>> roads_urban
>>
>> WHERE
>>
>> roads.the_geom && roads_urban.the_geom
>>
>> AND
>>
>> NOT INTERSECTS(roads.the_geom, roads_urban.the_geom);
>>
>> If anybody's got any tips on how to do this, or advice on where I'm 
>> going wrong....!
>>
>> Many thanks,
>>
>> Matt
>>
>> Matt Doughty
>>
>> 	
>>
>> GEOGRAMA S.L.
>>
>> Tel.: +34 945 13 13 72 652 77 14 15
>>
>> Fax: +34 945 23 03 40
>>
>> www.geograma.com
>>
>> 	
>>
>>
>>     
> ------------------------------------------------------------------------
>   
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>   
>>     
>
>   

-- 
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022




More information about the postgis-users mailing list