ThinkGeo.com    |     Documentation    |     Premium Support

SQLite layer disappears at zoom level 11

I have a basic WPF project which connects to a SQLite db as a layer. The layer is displayed just fine until I zoom in to level 11, at which point it disappears from the view. I’ve tried with the ne_110_land.sqlite file from ThinkGeo and that works fine in the same project (I can zoom past level 11 and the data still shows on the view). Is there something that needs to be done to a sqlite db to enable full zooming capabilities? I suspect something’s a bit off with my db.

Thanks,
Neil

Neil,

Can you open the Sqlite db with a GIS Viewer (QGIS for example) to see if it works as expected? If that works fine, can you send over your data to us (to support@thinkgeo.com)?

Thanks,
Ben

I’m having trouble with both my file and the ne_110_land.sqlite file in QGIS. I’ve never used it before, but there doesn’t seem to be a way to view a sqlite db.
Neil

Hi Neil,

What’s the “ne_110_land.sqlite file from ThinkGeo”? we attached frisco-restaurants.sqlite in the HowDoI sample, not sure where the ne_110_land.sqlite comes from.

I was wrong about the QGis, seems it cannot open a generic sqlite file even with Geometry column.

Can you simplify your code, disable the caches, remove other layers, etc, see if you can recreate the issue? I have a feeling it has something to do with the code. If still see the issues, you can send over the code to us and we can have a close look.

Thanks,
Ben

I found the ne_110* file in a help topic but I don’t recall which one it was. That one does work fine though. I’ve tried it with one layer and deleting the cache but my sqlite layers still drop out at zoom level 11. This is my code:

private async void mapView_Loaded(object sender, RoutedEventArgs e)
{
  mapView.MapUnit = GeographyUnit.Meter;
  var baseOverlay = new ThinkGeoCloudRasterMapsOverlay(<client>, <clientsecret>);
  baseOverlay.TileCache = new FileRasterTileCache(@".\cache", "basemap");
  mapView.Overlays.Add(baseOverlay);

  // Set the extent of the mapView
  mapView.CurrentExtent = MaxExtents.ThinkGeoMaps;

  SqliteFeatureLayer sqliteNodeLayer = new SqliteFeatureLayer(<SQLite file>, "Node", "id", "geometry");
  sqliteNodeLayer.Open();
  sqliteNodeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, 5, GeoBrushes.Red);
  sqliteNodeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(GeoPens.Red);
  sqliteNodeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(GeoBrushes.Red);
  sqliteNodeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
  ProjectionConverter projNode = new ProjectionConverter();
  projNode.InternalProjection.ProjString = Projection.GetLatLongProjString();
  projNode.ExternalProjection.ProjString = Projection.GetProjStringByEpsgSrid(3857);
  projNode.Close();
  sqliteNodeLayer.FeatureSource.ProjectionConverter = projNode;
  sqliteNodeLayer.FeatureSource.ProjectionConverter.Open();
  LayerOverlay sqliteOverlay = new LayerOverlay();
  sqliteOverlay.Layers.Add(sqliteNodeLayer);
  mapView.Overlays.Add(sqliteOverlay);

  SqliteFeatureLayer sqliteSectionLayer = new SqliteFeatureLayer(<SQLite file>, "InstSection", "id", "geometry");
  sqliteSectionLayer.Open();
  sqliteSectionLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(GeoPens.Blue);
  sqliteSectionLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
  ProjectionConverter projSect = new ProjectionConverter();
  projSect.InternalProjection.ProjString = Projection.GetLatLongProjString();
  projSect.ExternalProjection.ProjString = Projection.GetProjStringByEpsgSrid(3857);
  projSect.Close();
  sqliteSectionLayer.FeatureSource.ProjectionConverter = projSect;
  sqliteSectionLayer.FeatureSource.ProjectionConverter.Open();
  sqliteOverlay.Layers.Add(sqliteSectionLayer);
  mapView.Overlays.Add(sqliteOverlay);

  await mapView.RefreshAsync();
}

Hi Neil,

I noted some issues (for example: the same overlay were added twice to the map, layer.Open/Close were called unnecessarily), and I simplified the code to as following. Please have another try.

    private async void mapView_Loaded(object sender, RoutedEventArgs e)
    {
        mapView.MapUnit = GeographyUnit.Meter;
        var baseOverlay = new ThinkGeoCloudRasterMapsOverlay(< client >, < clientsecret >);
        baseOverlay.TileCache = new FileRasterTileCache(@".\cache", "basemap");
        mapView.Overlays.Add(baseOverlay);

        // Set the extent of the mapView
        mapView.CurrentExtent = MaxExtents.ThinkGeoMaps;

        SqliteFeatureLayer sqliteNodeLayer = new SqliteFeatureLayer(< SQLite file >, "Node", "id", "geometry");
        sqliteNodeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, 5, GeoBrushes.Red);
        sqliteNodeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(GeoPens.Red);
        sqliteNodeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(GeoBrushes.Red);
        sqliteNodeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        sqliteNodeLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(4326, 3857);
        LayerOverlay sqliteOverlay = new LayerOverlay();
        sqliteOverlay.Layers.Add(sqliteNodeLayer);
        mapView.Overlays.Add(sqliteOverlay);

        SqliteFeatureLayer sqliteSectionLayer = new SqliteFeatureLayer(< SQLite file >, "InstSection", "id", "geometry");
        sqliteSectionLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(GeoPens.Blue);
        sqliteSectionLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        sqliteSectionLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(4326, 3857);
        sqliteOverlay.Layers.Add(sqliteSectionLayer);

        await mapView.RefreshAsync();
    }

If you still see the issues, try just loading the sqllite data without any reprojection, see if it shows up everything correctly. If it does, that means something is going on with the projection

  private async void mapView_Loaded(object sender, RoutedEventArgs e)
  {
      mapView.MapUnit = GeographyUnit.DecimalDegree;

      SqliteFeatureLayer sqliteSectionLayer = new SqliteFeatureLayer(< SQLite file >, "InstSection", "id", "geometry");
      sqliteSectionLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(GeoPens.Blue);
      sqliteSectionLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

      LayerOverlay sqliteOverlay = new LayerOverlay();
      sqliteOverlay.Layers.Add(sqliteSectionLayer);
      mapView.Overlays.Add(sqliteOverlay);

      sqliteSectionLayer.Open();
      mapView.CurrentExtent = sqliteSectionLayer.GetBoundingBox();
      await mapView.RefreshAsync();
  }

Thanks,
Ben

I tried the code you posted and I still get the same results (the sqlite layer disappears after zooming). However, I also tried it without the projection and saw that it stayed visible until I couldn’t zoom any more (using the default zoom levels). I’m not sure if there’s much different that can be done with the projection, or is there?

Hi Neil,

If the single layer without projection works fine, let me know if the single layer with projection works.

    private async void mapView_Loaded(object sender, RoutedEventArgs e)
    {
        mapView.MapUnit = GeographyUnit.Meter;

        SqliteFeatureLayer sqliteSectionLayer = new SqliteFeatureLayer(< SQLite file >, "InstSection", "id", "geometry");
        sqliteSectionLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(GeoPens.Blue);
        sqliteSectionLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        sqliteSectionLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(4326, 3857);

        LayerOverlay sqliteOverlay = new LayerOverlay();
        sqliteOverlay.Layers.Add(sqliteSectionLayer);
        mapView.Overlays.Add(sqliteOverlay);

        sqliteSectionLayer.Open();
        mapView.CurrentExtent = sqliteSectionLayer.GetBoundingBox();
        await mapView.RefreshAsync();
    }

Thanks,
Ben

No, it gives the same result as before (disappears after zooming). Multiple layers are ok without the projection.

Thanks,
Neil

Hi Neil, it seems it has something to do with the projection, but I don’t have any clue, any chance you send over the data to us(support@thinkgeo.com) to dive in?

Sounds like a plan - I’ll drop that over in a bit. Thanks for all your help so far.

I just sent it over, hopefully the attachment makes it through (the sqlite db).

Hi Neil,

I got your data and I found its spatial index is not set up correctly. Specifically, the minx/maxx/miny/maxy in idx_instsection_geometry table is incorrect. I think it at least need to be REAL instead of INT, because the geometry in your datatable is based on decimal degrees which means an integer-based extent will lose lost of precision and is not enough to extinguish between other geometries. Update the index and everything should be fine.

Thanks,
Ben

That was right on the money. My code to create the index was using the rtree_i32. I must have been writing out different data - it’s been a few years since I used that code. Thanks for your help with this!

You are welcome, Neil!