Skip to content

Spatialite validity checks geopaparazzi specific

mj10777 edited this page Oct 26, 2018 · 33 revisions

--> 'List of Sql-Commands'

--> 'List of Themes'

--> 'List of Database-Designing'

--> 'List of Geopaparazzi Specific Themes'


The intention of the Page to to explain the methods / reasons

  • for a valid geometry to be shown
  • for a invalid geometry not to be shown
  • what types of repairs (where practical) will be done
    • what these condition must be fulfilled
  • the different ways that it will handle
    • pre-spatialite 4.*
    • spatialite starting with 4.0

  • SpatialiteDatabaseHandler
    • is the container for a spatialite, but also for a mbtiles, Database
    • during construction it will call
      • DaoSpatialite.checkDatabaseTypeAndValidity
        • the Database connection will be given *and
        • 2 HashMap<String,String> to store the results
          • spatialVectorMap
            • will contain all information about all the valid geometries of this Database
              • each entry can be used to create a SpatialVectorTable
                • a long term goal should be, to change that constructor to receive a
                  • Map.Entry<String, String> vector_entry
                    • where the needed parsing can be done
          • spatialVectorMapErrors
            • will contain all information about all the invalid geometries of this Database
              • this could be used to inform users about geometries that have failed

  • DaoSpatialite.checkDatabaseTypeAndValidity
    • the first task is to determine what type of database we have

      • gpkg or spatialite
        • for spatialite we check if
          • the tables: geometry_columns and layers_statistics exist
          • the views: vector_layers_statistics and vector_layers exist
            • if this is the case SPATIALITE4 is assumed
              • normally layers_statistics will not exist
                • but pre-spatialite 4.* that have been changed by a spatialite 4.* software often do
          • if geometry_columns exists and vector_layers_statistics and vector_layers do not exist
            • if this is the case SPATIALITE3 is assumed
    • gpkg will return at this point with the value SpatialiteDatabaseType.GEOPACKAGE

      • SpatialiteDatabaseHandler.collectGpkgTables()
        • will later be called to read gpkg specfic information
    • the second task is to to read the geometries

      • SPATIALITE3: getSpatialVectorMap_V3 will be called
        • will take care of the pre-spatialite collection of the geometry information
          • after which it will return with SpatialiteDatabaseType.SPATIALITE3
      • SPATIALITE4: getSpatialVectorMap_V4 will be called
        • will take care of the spatialite 4.* collection of the geometry information
        • if a raster_coverages was found
          • 'RasterLite2 Layers-Querys'
            • information will be colletted for a possible future RasterLite2 support
          • after which it will return with SpatialiteDatabaseType.SPATIALITE4
      • GEOPACKAGE: getGeoPackageMap_R10 will be called
        • will take care of the GeoPackage R10 collection of the geometry/tiles information
    • if no valid entries were found for a Database

      • SpatialiteDatabaseType.UNKNOWN will be returned
        • thus the Database will be ignored, since there is nothing to show

  • getSpatialVectorMap_V3

  • a apposed to spatialite 4 Databases, the collection of the geometries must be done in 2 steps

    • one for SpatialViews
    • one for SpatialTables
    • also a pre-condition for this to work is that a layers_statistics table exists
      • thus the UpdateLayerStatistics is done beforehand
  • every else is done in the same way as getSpatialVectorMap_V4


  • getSpatialVectorMap_V4

    • the first task here is to collect the list of invalid geometries
      • this will be used later to try to resolve and resolvable problems
    • the second task is to collect the list of valid geometries
      • for this the 'Spatialite specific Vector-Layer query is used'
        • this will return 'description in the VECTOR_LAYERS_QUERYS Page'
        • vector_key sample: segments_berlin_1928;soldner_segment;SpatialView;ROWID;-1
        • vector_data sample: 2;2;3068;1;
        • vector_extent sample: 349;-4.24035848509084,1208.43017876675,49230.1528101726,38747.9589061869;2014-04-15T05:21:54.603Z
      • when a SpatialView is found : DaoSpatialite.getViewRowid() will be called and
        • replace ROWID;-1 with (in this case) id_segment;1
      • a check is done if vector_extent is not NULL (the only portion of the query that could fail)
        • if correct these values will be added to spatialVectorMap with
          • spatialVectorMap.put(vector_key,vector_data+vector_extent);
  • the last task is to check if spatialVectorMapErrors is not empty

    • if VECTOR_LAYERS_QUERY_MODE > 0
      • DaoSpatialite.getSpatialVectorMap_Correct() will be called

  • getSpatialVectorMap_Correct

Possible error corrections

  • for this a global static var has been created
    • VECTOR_LAYERS_QUERY_MODE
      • 0 = strict
        • will only use the valid entries
      • 1 = tolerant
        • the bounds will be queried with DaoSpatialite.SpatialiteRetrieveBounds()
          • this can be very time consuming
      • 2 = corrective [at the moment default]
        • for each geometry: DaoSpatialite.SpatialiteUpdateLayerStatistics() will be called
          • SpatialiteCountGeometries() will be called
            • this will return the amount of geometries that are NOT NULL
              • only when > 0: will any recovery attempt be made

--

  • a User-Setting should be created for the setting of
    • DaoSpatialite.VECTOR_LAYERS_QUERY_MODE
      • default = 0: no checking, only valid geometries will be returned
    • the user should set this to
      • 2 = corrective when:
        • a new Database has been added and it does not show up
        • when the Application is restarted, recoveries - where possible - will be attempted during
          • SpatialDatabasesManager.init()
            • after which MapsDirManager.init() should set
              • DaoSpatialite.VECTOR_LAYERS_QUERY_MODE back to 0
          • if a problem is not resolved the first time around
            • it will never be resolved

  • SpatialiteRetrieveBounds
    • it is possible that all geometries of a table are NULL
      • a table column has been prepared, but not filled
        • this is to be considered invalid
          • vector_extent is empty
    • called from
      • getSpatialiteUpdateLayerStatistics
      • getSpatialVectorMap_Correct
        • where the spatialVectorMap.put(vector_key,vector_data+vector_extent); is done

Conditions where no attempt to recover will be made and the geometry column will therefore not be loaded

  • the table has a defined geometry
    • the row count is > 0
    • all these geometries are NULL
  • the table row count is == 0
  • the spatial_index_enabled == 0

2014-05-11: Mark Johnson, Berlin Germany


Clone this wiki locally