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))

closed as off-topic by PolyGeo Oct 12 '17 at 10:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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