<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Hi Ricardo,<br><br>Having been through the mailing list's archives myself over the last few weeks, i came up with the following recipe:<br><br>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8">
<title></title>
<meta name="GENERATOR" content="OpenOffice.org 3.1 (Linux)">
<style type="text/css">
<!--
@page { margin: 0.79in }
P { margin-bottom: 0.08in }
P.code-western { margin-bottom: 0in; background: #f3f3f3; border: 1px solid #000000; padding: 0.02in; font-family: "Courier New", monospace; font-size: 10pt; so-language: zxx; line-height: 100%; page-break-before: auto }
P.code-cjk { margin-bottom: 0in; background: #f3f3f3; border: 1px solid #000000; padding: 0.02in; line-height: 100%; page-break-before: auto }
P.code-ctl { margin-bottom: 0in; background: #f3f3f3; border: 1px solid #000000; padding: 0.02in; line-height: 100%; page-break-before: auto }
--></style>First you dump all multipolygons into polygons:<br><br>SELECT<br> (ST_Dump(the_geom)).geom AS the_geom<br>INTO polygon_table<br>FROM multipolygon_table <br><br>and create an index on that one<br><br>CREATE INDEX geo_idx_polygon_temp ON polygon_table_temp USING GIST (the_geom);<br>VACUUM ANALYZE polygon_table_temp;<br><br>then you create a new table that contains the borders using ST_Intersection:<br><br>CREATE TABLE borders AS <br>SELECT<br> ST_Intersection(t1.the_geom,t2.the_geom) AS the_geom<br>FROM<br> polygon_table_temp AS t1,<br> polygon_table_temp AS t2<br>WHERE<br> t1.the_geom && t2.the_geom;<br><br>These borders are duplicated, as the intersection is computed twice (A intersects B and B intersects A). Also contains records of geometry other than multilinestring<br><br>DELETE FROM borders WHERE GeometryType(the_geom) <> 'MULTILINESTRING'::text; <br>SELECT Populate_Geometry_Columns('borders'::regclass);<br><br>ALTER TABLE borders ADD COLUMN gid SERIAL;<br>
ALTER TABLE borders ADD PRIMARY KEY (gid);<br><br>CREATE INDEX geo_idx_borders ON borders USING GIST (the_geom);<br>VACUUM ANALYZE borders;<br><br> so remove duplicates:<br><br>DELETE FROM borders WHERE<br>borders.gid < <br>(SELECT MAX(b.gid )<br> FROM borders b <br> WHERE b.the_geom && borders.the_geom <br> AND ST_Equals(borders.the_geom, b.the_geom));<br><br>REINDEX TABLE borders;<br>VACUUM ANALYZE borders;<br><br>That should do it. Thanks to previous postings to this mailing list!<br><br>regards,<br><br>Edward<br><br><br><br><hr id="stopSpelling">Date: Thu, 24 Jun 2010 16:53:54 -0300<br>From: vilella.ricardo@gmail.com<br>To: postgis-users@postgis.refractions.net<br>Subject: [postgis-users] Polygon to line<br><br><span id="ecxresult_box" class="ecxshort_text"><span style="" title="">Hi all, is the first time I use the list. I have a polygon that represent a country, if i want extract only the sides that touch with other polygon. How i have to do? The result should be a MultiLineString or a LineString representing the limits of the country but without the coast line if it has one.</span></span> I tried with ST_Touches but i can't get it work.<br> </body>
</html>