{"id":482,"date":"2015-05-20T21:23:19","date_gmt":"2015-05-20T19:23:19","guid":{"rendered":"http:\/\/hannes.enjoys.it\/blog\/?p=482"},"modified":"2015-05-20T21:24:12","modified_gmt":"2015-05-20T19:24:12","slug":"merge-gml-files-into-one-sqlite-or-spatialite-file","status":"publish","type":"post","link":"https:\/\/hannes.enjoys.it\/blog\/2015\/05\/merge-gml-files-into-one-sqlite-or-spatialite-file\/","title":{"rendered":"Merge GML files into one SQLite or Spatialite file"},"content":{"rendered":"<p>For example the <a href=\"http:\/\/inspire.daten-hamburg.de\/DE_HH_Downloaddienst_INSPIRE_A3_2_Gebaeude\/NAS_gebaeude.zip\">buildings in Hamburg, Germany<\/a>:<\/p>\n<pre><code>layer=$1\r\nfor file in *.xml\r\ndo\r\n&nbsp;if [ -f \"${layer}\".spatialite ]\r\n&nbsp;then\r\n&nbsp;&nbsp;ogr2ogr -f \"SQLite\" -update -append \"${layer}\".spatialite \"${file}\" \"${layer}\" -dsco SPATIALITE=YES\r\n&nbsp;else\r\n&nbsp;&nbsp;ogr2ogr -a_srs EPSG:25832 -f \"SQLite\" \"${layer}\".spatialite \"${file}\" \"${layer}\" -dsco SPATIALITE=YES\r\n&nbsp;fi\r\ndone<\/code><\/pre>\n<p>Remove the <code>-dsco SPATIALITE=YES<\/code> and change the output filename for SQLite. QGIS can work with both.<\/p>\n<p><code>$ bash mergexmltospatialite.sh AX_Gebaeude<\/code><\/p>\n<p>Be aware that Spatialite is much more sensitive to geometric problems. You might get things like <\/p>\n<blockquote><p><code>ERROR 1: sqlite3_step() failed:<br \/>\n  ax_gebaeude.GEOMETRY violates Geometry constraint [geom-type or SRID not allowed] (19)<br \/>\nERROR 1: ROLLBACK transaction failed: cannot rollback - no transaction is active<br \/>\nERROR 1: Unable to write feature 1712 from layer AX_Gebaeude.<\/p>\n<p>ERROR 1: Terminating translation prematurely after failed translation of layer AX_Gebaeude (use -skipfailures to skip errors)<\/code><\/p><\/blockquote>\n<p>but on the other hand, you get spatial indexing which makes queries or high zoom interaction much quicker.<\/p>\n<p>Be aware that if you try to merge files into a Shapefile and fields are getting truncated, those fields will only be filled with data for the first file you merge. On the later files OGR will try to match the input field names to the merged file&#8217;s fieldnames, notice the difference and discard them. If you still want to convert to Shapefiles, check out the <code>-fieldTypeToString IntegerList,StringList<\/code> options.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For example the buildings in Hamburg, Germany: layer=$1 for file in *.xml do &nbsp;if [ -f &#8220;${layer}&#8221;.spatialite ] &nbsp;then &nbsp;&nbsp;ogr2ogr -f &#8220;SQLite&#8221; -update -append &#8220;${layer}&#8221;.spatialite &#8220;${file}&#8221; &#8220;${layer}&#8221; -dsco SPATIALITE=YES &nbsp;else &nbsp;&nbsp;ogr2ogr -a_srs EPSG:25832 -f &#8220;SQLite&#8221; &#8220;${layer}&#8221;.spatialite &#8220;${file}&#8221; &#8220;${layer}&#8221; -dsco SPATIALITE=YES &nbsp;fi done Remove the -dsco SPATIALITE=YES and change the output filename for SQLite. QGIS can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,24,29,30,10,31,1],"tags":[],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-commandline","category-gdal","category-gis","category-ogr","category-open-data","category-qgis","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/comments?post=482"}],"version-history":[{"count":11,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/482\/revisions"}],"predecessor-version":[{"id":494,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/482\/revisions\/494"}],"wp:attachment":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/media?parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/categories?post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/tags?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}