<p>I think the issue happens because some boundary linestrings can not be merged as rings.</p>
<div class="highlight highlight-source-sql"><pre><span class="pl-k">select</span> string_agg(distinct name, <span class="pl-s"><span class="pl-pds">'</span>, <span class="pl-pds">'</span></span>) <span class="pl-k">as</span> name, ST_IsClosed(ST_LineMerge(ST_Union(way))), ST_IsSimple(ST_LineMerge(ST_Union(way))) <span class="pl-k">from</span> planet_osm_line <span class="pl-k">where</span> admin_level<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">'</span>2<span class="pl-pds">'</span></span> <span class="pl-k">and</span> boundary<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">'</span>administrative<span class="pl-pds">'</span></span> <span class="pl-k">and</span> tags<span class="pl-k">-</span><span class="pl-k">></span><span class="pl-s"><span class="pl-pds">'</span>name:en<span class="pl-pds">'</span></span> <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">'</span>Spain<span class="pl-pds">'</span></span> <span class="pl-k">group by</span> osm_id;

  name  | st_isclosed | st_issimple 
<span class="pl-c"><span class="pl-c">--</span>------+-------------+-------------</span>
 España | f           | t
(<span class="pl-c1">1</span> row)</pre></div>
<div class="highlight highlight-source-sql"><pre><span class="pl-k">select</span> ST_AsGeoJSON(ST_MakePolygon(ST_LineMerge(ST_Union(way)))) <span class="pl-k">from</span> planet_osm_line <span class="pl-k">where</span> admin_level<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">'</span>2<span class="pl-pds">'</span></span> <span class="pl-k">and</span> boundary<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">'</span>administrative<span class="pl-pds">'</span></span> <span class="pl-k">and</span> tags<span class="pl-k">-</span><span class="pl-k">></span><span class="pl-s"><span class="pl-pds">'</span>name:en<span class="pl-pds">'</span></span> <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">'</span>Spain<span class="pl-pds">'</span></span> <span class="pl-k">group by</span> osm_id;

ERROR:  Shell is not a <span class="pl-k">line</span></pre></div>
<p>Does anybody know how to close unclosed linestrings automatically?</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/osm2pgsql/issues/866#issuecomment-425724740">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AD2-7p2F5BLCwatdTHCE8SuUcEezwBj8ks5ugNV8gaJpZM4WXds3">mute the thread</a>.<img src="https://github.com/notifications/beacon/AD2-7igAvFon8LEXsnmSL8OXwOfj3f6Jks5ugNV8gaJpZM4WXds3.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/openstreetmap/osm2pgsql","title":"openstreetmap/osm2pgsql","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/openstreetmap/osm2pgsql"}},"updates":{"snippets":[{"icon":"PERSON","message":"@ihor-nahuliak in #866: I think the issue happens because some boundary linestrings can not be merged as rings.\r\n```sql\r\nselect string_agg(distinct name, ', ') as name, ST_IsClosed(ST_LineMerge(ST_Union(way))), ST_IsSimple(ST_LineMerge(ST_Union(way))) from planet_osm_line where admin_level='2' and boundary='administrative' and tags-\u003e'name:en' = 'Spain' group by osm_id;\r\n\r\n  name  | st_isclosed | st_issimple \r\n--------+-------------+-------------\r\n España | f           | t\r\n(1 row)\r\n```\r\n```sql\r\nselect ST_AsGeoJSON(ST_MakePolygon(ST_LineMerge(ST_Union(way)))) from planet_osm_line where admin_level='2' and boundary='administrative' and tags-\u003e'name:en' = 'Spain' group by osm_id;\r\n\r\nERROR:  Shell is not a line\r\n```\r\nDoes anybody know how to close unclosed linestrings automatically?"}],"action":{"name":"View Issue","url":"https://github.com/openstreetmap/osm2pgsql/issues/866#issuecomment-425724740"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/osm2pgsql/issues/866#issuecomment-425724740",
"url": "https://github.com/openstreetmap/osm2pgsql/issues/866#issuecomment-425724740",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [openstreetmap/osm2pgsql] Missing MultiPolygons (#866)",
"sections": [
{
"text": "",
"activityTitle": "**ihor-nahuliak**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@ihor-nahuliak",
"facts": [

]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"openstreetmap/osm2pgsql\",\n\"issueId\": 866,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close issue",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"openstreetmap/osm2pgsql\",\n\"issueId\": 866\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/openstreetmap/osm2pgsql/issues/866#issuecomment-425724740"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 375249719\n}"
}
],
"themeColor": "26292E"
}
]</script>