[gdal-dev] Missing features after copying layers from Shapefiles to SQLite
Jukka Rahkonen
jukka.rahkonen at mmmtike.fi
Sun Mar 2 21:37:39 PST 2014
Nik Sands <nixanz <at> nixanz.com> writes:
>
> Hi all,
>
> I'm planning to switch from using a standard file format of Shapefiles to
Spatialite for internal storage
> of spatial data.
>
> When importing from other formats, the app attempts to convert these to
SQLite (Spatialite) using
> 'OGR_DS_CopyLayer' to copy each layer from the source data set to a new
layer in the new SQLite dataset.
>
> However, when converting Shapefiles to SQLite, it only copies across about
a third of the features for many
> of the layers and therefore the new data set is of no use.
>
> The relevant code and output is below.
>
> I'm at a loss to figure out what is going wrong here and I'd be grateful
is somebody could assist in getting
> this to work as expected (or am I doing the wrong thing completely?).
>
> NB: This is using Spatialite on iOS (simulator).
>
> When I use ogr2ogr on Mac OS X with SQLite (without Spatialite) it works
fine and doesn't miss any features.
>
> Cheers,
> Nik.
>
> CODE:
>
> OGRLayerH sourceLayer = OGR_DS_GetLayer(ds, i);
> int sourceFeatureCount = OGR_L_GetFeatureCount(sourceLayer, YES);
>
> OGR_DS_CopyLayer(destDS, sourceLayer, OGR_L_GetName(sourceLayer), NULL);
>
> OGRLayerH destLayer = OGR_DS_GetLayerByName(destDS,
OGR_L_GetName(sourceLayer));
> printf("sourceFeatureCount: %d\n", sourceFeatureCount);
> printf(" destFeatureCount: %d\n", OGR_L_GetFeatureCount(destLayer, YES));
>
> OUTPUT:
>
> sourceFeatureCount: 3882
> destFeatureCount: 1200
>
Hi,
My guess is that CopyLayer is making 200 feature sized transactions and only
6 transactions are accepted by Spatialite which makes 1200 features. The
rest transactions are not accepted for some reason. With Spatialite my guess
is that it complains about constraints and some of the features do not share
the same geometry type and SRID. Perhaps trying to write multipolygons into
a layer that accepts only polygons or vice versa.
-Jukka Rahkonen-
More information about the gdal-dev
mailing list