2

I am using a spatialite db to perform a union and dissolve over a vector file. The vector inside the db looks like this: enter image description here

when I export the table with: ogr2ogr -f "ESRI Shapefile" -overwrite output.shp db.sqlite -dsco SPATIALITE=yes -sql "SELECT * FROM unidos" -nlt MULTIPOLYGON

the resulting shapefile has some of the holes filled, like in the next image enter image description here

What can be wrong? I have checked the input file and it is OK. I mean, the holes are actually holes. And, why some holes remains, while others are filled if they are all created the same way.


This is the code I am using to generate the initial vector file: The input raster file is binary.

import os
from osgeo import ogr,gdal,osr
import time

strtime= time.time()

inputdir= "/home/queimadas/Dropbox/areaquemada/Code/JoinFeaturesSpatially/NEW2"
inputraster= "221_067_2015-01-24_QMENC_0.30_0.80.tif"
outshp= "outshp.shp"


ds= gdal.Open("%s/%s"%(inputdir,inputraster))
geoproj= ds.GetProjection()

Sdrv= ogr.GetDriverByName("ESRI Shapefile")
lyname= "%s/%s"%(inputdir,outshp)
shpfn= lyname
if os.path.exists(shpfn):
    Sdrv.DeleteDataSource(shpfn)

dst_ds= Sdrv.CreateDataSource(shpfn)
srs= osr.SpatialReference(wkt= geoproj)
dst_layer= dst_ds.CreateLayer(lyname, srs)  
fd= ogr.FieldDefn('DN', ogr.OFTInteger)
dst_layer.CreateField(fd)

gdal.Polygonize(ds.GetRasterBand(1), None, dst_layer, 0, [], callback= None)

def procfeat(feat):
    if dst_layer.GetFeature(feat).GetFieldAsInteger('DN') == 0:
        dst_layer.DeleteFeature(feat)

xs= xrange(dst_layer.GetFeatureCount())

map(procfeat, xs)
dst_ds.ExecuteSQL('REPACK %s'%dst_layer.GetName())
print "time: %.3f"%(time.time()-strtime)

Here's a WKT for a feature that it is OK in the input file.

POLYGON((244318.54237071701209061 8890674.63205884955823421,244288.54237071701209061 8890674.63205884955823421,244288.54237071701209061 8890704.63205884955823421,244198.54237071701209061 8890704.63205884955823421,244198.54237071701209061 8890734.63205884955823421,244168.54237071701209061 8890734.63205884955823421,244168.54237071701209061 8890764.63205884955823421,244198.54237071701209061 8890764.63205884955823421,244228.54237071701209061 8890764.63205884955823421,244228.54237071701209061 8890794.63205884955823421,244198.54237071701209061 8890794.63205884955823421,244198.54237071701209061 8890854.63205884955823421,244228.54237071701209061 8890854.63205884955823421,244258.54237071701209061 8890854.63205884955823421,244258.54237071701209061 8890884.63205884955823421,244288.54237071701209061 8890884.63205884955823421,244288.54237071701209061 8890854.63205884955823421,244318.54237071701209061 8890854.63205884955823421,244318.54237071701209061 8890824.63205884955823421,244378.54237071701209061 8890824.63205884955823421,244378.54237071701209061 8890854.63205884955823421,244408.54237071701209061 8890854.63205884955823421,244408.54237071701209061 8890884.63205884955823421,244438.54237071701209061 8890884.63205884955823421,244438.54237071701209061 8890854.63205884955823421,244528.54237071701209061 8890854.63205884955823421,244528.54237071701209061 8890884.63205884955823421,244558.54237071701209061 8890884.63205884955823421,244558.54237071701209061 8890914.63205884955823421,244588.54237071701209061 8890914.63205884955823421,244588.54237071701209061 8890884.63205884955823421,244648.54237071701209061 8890884.63205884955823421,244648.54237071701209061 8890914.63205884955823421,244738.54237071701209061 8890914.63205884955823421,244738.54237071701209061 8890884.63205884955823421,244858.54237071701209061 8890884.63205884955823421,244858.54237071701209061 8890854.63205884955823421,244888.54237071701209061 8890854.63205884955823421,244888.54237071701209061 8890824.63205884955823421,244918.54237071701209061 8890824.63205884955823421,244918.54237071701209061 8890764.63205884955823421,244888.54237071701209061 8890764.63205884955823421,244828.54237071701209061 8890764.63205884955823421,244828.54237071701209061 8890794.63205884955823421,244768.54237071701209061 8890794.63205884955823421,244768.54237071701209061 8890734.63205884955823421,244738.54237071701209061 8890734.63205884955823421,244738.54237071701209061 8890704.63205884955823421,244648.54237071701209061 8890704.63205884955823421,244648.54237071701209061 8890734.63205884955823421,244678.54237071701209061 8890734.63205884955823421,244678.54237071701209061 8890764.63205884955823421,244618.54237071701209061 8890764.63205884955823421,244618.54237071701209061 8890704.63205884955823421,244588.54237071701209061 8890704.63205884955823421,244588.54237071701209061 8890674.63205884955823421,244558.54237071701209061 8890674.63205884955823421,244468.54237071701209061 8890674.63205884955823421,244468.54237071701209061 8890644.63205884955823421,244438.54237071701209061 8890644.63205884955823421,244408.54237071701209061 8890644.63205884955823421,244408.54237071701209061 8890614.63205884955823421,244318.54237071701209061 8890614.63205884955823421,244318.54237071701209061 8890674.63205884955823421),(244318.54237071701209061 8890674.63205884955823421,244378.54237071701209061 8890674.63205884955823421,244378.54237071701209061 8890704.63205884955823421,244408.54237071701209061 8890704.63205884955823421,244408.54237071701209061 8890764.63205884955823421,244378.54237071701209061 8890764.63205884955823421,244378.54237071701209061 8890734.63205884955823421,244348.54237071701209061 8890734.63205884955823421,244348.54237071701209061 8890704.63205884955823421,244318.54237071701209061 8890704.63205884955823421,244318.54237071701209061 8890674.63205884955823421),(244468.54237071701209061 8890764.63205884955823421,244468.54237071701209061 8890704.63205884955823421,244528.54237071701209061 8890704.63205884955823421,244528.54237071701209061 8890764.63205884955823421,244468.54237071701209061 8890764.63205884955823421))

After importing into the spatialite db, union and exporting again the WKT is as follows.

POLYGON((244318.54237071701209061 8890674.63205884955823421,244288.54237071701209061 8890674.63205884955823421,244288.54237071701209061 8890704.63205884955823421,244198.54237071701209061 8890704.63205884955823421,244198.54237071701209061 8890734.63205884955823421,244168.54237071701209061 8890734.63205884955823421,244168.54237071701209061 8890764.63205884955823421,244198.54237071701209061 8890764.63205884955823421,244228.54237071701209061 8890764.63205884955823421,244228.54237071701209061 8890794.63205884955823421,244198.54237071701209061 8890794.63205884955823421,244198.54237071701209061 8890854.63205884955823421,244228.54237071701209061 8890854.63205884955823421,244258.54237071701209061 8890854.63205884955823421,244258.54237071701209061 8890884.63205884955823421,244288.54237071701209061 8890884.63205884955823421,244288.54237071701209061 8890854.63205884955823421,244318.54237071701209061 8890854.63205884955823421,244318.54237071701209061 8890824.63205884955823421,244378.54237071701209061 8890824.63205884955823421,244378.54237071701209061 8890854.63205884955823421,244408.54237071701209061 8890854.63205884955823421,244408.54237071701209061 8890884.63205884955823421,244438.54237071701209061 8890884.63205884955823421,244438.54237071701209061 8890854.63205884955823421,244528.54237071701209061 8890854.63205884955823421,244528.54237071701209061 8890884.63205884955823421,244558.54237071701209061 8890884.63205884955823421,244558.54237071701209061 8890914.63205884955823421,244588.54237071701209061 8890914.63205884955823421,244588.54237071701209061 8890884.63205884955823421,244648.54237071701209061 8890884.63205884955823421,244648.54237071701209061 8890914.63205884955823421,244738.54237071701209061 8890914.63205884955823421,244738.54237071701209061 8890884.63205884955823421,244858.54237071701209061 8890884.63205884955823421,244858.54237071701209061 8890854.63205884955823421,244888.54237071701209061 8890854.63205884955823421,244888.54237071701209061 8890824.63205884955823421,244918.54237071701209061 8890824.63205884955823421,244918.54237071701209061 8890764.63205884955823421,244888.54237071701209061 8890764.63205884955823421,244828.54237071701209061 8890764.63205884955823421,244828.54237071701209061 8890794.63205884955823421,244768.54237071701209061 8890794.63205884955823421,244768.54237071701209061 8890734.63205884955823421,244738.54237071701209061 8890734.63205884955823421,244738.54237071701209061 8890704.63205884955823421,244648.54237071701209061 8890704.63205884955823421,244648.54237071701209061 8890734.63205884955823421,244678.54237071701209061 8890734.63205884955823421,244678.54237071701209061 8890764.63205884955823421,244618.54237071701209061 8890764.63205884955823421,244618.54237071701209061 8890704.63205884955823421,244588.54237071701209061 8890704.63205884955823421,244588.54237071701209061 8890674.63205884955823421,244558.54237071701209061 8890674.63205884955823421,244468.54237071701209061 8890674.63205884955823421,244468.54237071701209061 8890644.63205884955823421,244438.54237071701209061 8890644.63205884955823421,244408.54237071701209061 8890644.63205884955823421,244408.54237071701209061 8890614.63205884955823421,244318.54237071701209061 8890614.63205884955823421,244318.54237071701209061 8890674.63205884955823421),(244318.54237071701209061 8890674.63205884955823421,244378.54237071701209061 8890674.63205884955823421,244378.54237071701209061 8890704.63205884955823421,244408.54237071701209061 8890704.63205884955823421,244408.54237071701209061 8890764.63205884955823421,244378.54237071701209061 8890764.63205884955823421,244378.54237071701209061 8890734.63205884955823421,244348.54237071701209061 8890734.63205884955823421,244348.54237071701209061 8890704.63205884955823421,244318.54237071701209061 8890704.63205884955823421,244318.54237071701209061 8890674.63205884955823421))

With another feature on top (where the hole was)

POLYGON((244468.54237071701209061 8890764.63205884955823421,244528.54237071701209061 8890764.63205884955823421,244528.54237071701209061 8890704.63205884955823421,244468.54237071701209061 8890704.63205884955823421,244468.54237071701209061 8890764.63205884955823421))

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Emiliano
  • 137
  • 1
  • 6
  • Try to find one polygon which is exported in a wrong way and add that as well known text into your question. – user30184 Jun 20 '15 at 18:33
  • Those are pretty complex polygons, also in UTM coordinates. Besides the WKT will tell you exactly the same thing you are seeing in these images. – Emiliano Jun 22 '15 at 17:26
  • I do not want to see your polygons. I want to repeat the error from source data myself and understand what happens. – user30184 Jun 22 '15 at 17:33
  • Ok, there you have an example. – Emiliano Jun 22 '15 at 18:24
  • Another weird behaviour is that inside the spatialite db, both tables have all holes. The export command is the problem. – Emiliano Jun 22 '15 at 18:30
  • I have used the same approach of http://gis.stackexchange.com/questions/50290/merging-adjacent-polygons-in-shapefile-that-has-been-split-at-tile-boundaries to solve this situation. – Emiliano Jun 23 '15 at 13:42
  • I can't reproduce that error. I saved that WKT polygon into shapefile and converted it into Spatialite with ogr2ogr (GDAL 2.0) and also by importing the shapefile with spatialite-gui 1.8.0-devel. Then I exported data out from Spatialite with ogr2ogr and spatialite-gui. For me the hole remains always as a hole. Only thing I can imagine is that the ring orientation is wrong in your original data and inner ring (hole) is written as outer ring or something. I fear it is impossible to do more than this without getting grip on your original data. – user30184 Jun 23 '15 at 14:04
  • @user30184 how can I send you the data? I have no problem with that. I have solved by using PostGIS but I am interested in the other approach as well. – Emiliano Jun 23 '15 at 15:40
  • I have solved using .elemgeo dot macros for spatialite. Importing with ogr2ogr, processing inside spatialite and then exporting again with ogr2ogr – Emiliano Jun 23 '15 at 17:04

0 Answers0