Analyzing Exported Shapefile - geopaparazzi/Spatialite-Tasks-with-Sql-Scripts GitHub Wiki

Analyzing a Shape File

  • You can download the Shape file used in this sample here:

<-- 'Index Page for Importing Shapefiles'

<-- 'creating a Shapefile from spatialite database from using QGIS'

--> 'Using spatialite_gui for Shapefiles'


As we all know, all roads leads toward Rome

  • the question is only which should be taken for this case:
    • ogrinfo
      • a gdal tool for Vector Formats (gdalinfo being only for Rasters)
    • QGIS
      • where the Shapefile can be loaded
    • spatialite_gui
      • with use of virtualshape or
      • the gui Function Load Shapefile

ogrinfo

  • the following command will list the first record
    • including the geometry as WKT (Well Known Text)
      • -al: List all features of all layers
        • with Features the fields are meant
      • -where: SQL WHERE statement. Only features matching the attribute query will be reported
        • here we will show the first record with 'fid in(0)'
          • fid: when using ogr this virtual field will always exists
            • and starts with 0
            • 'fid' is a special field recognized by OGR SQL.

Since our goal is to find out

  • how the Shapefile is structures (i.e. which fields it has)
    • we use this general solution on any ogr source
ogrinfo -al -where 'fid in(0)' berlin_plz_segments/berlin_plz_segments.shp

INFO: Open of `berlin_plz_segments/berlin_plz_segments.shp'
      using driver `ESRI Shapefile' successful.

Layer name: berlin_plz_segments
Geometry: Line String
Feature Count: 1
Extent: (18405.673758, 16709.072001) - (30386.451847, 26751.219329)
Layer SRS WKT:
PROJCS["DHDN_Soldner_Berlin",
    GEOGCS["GCS_DHDN",
        DATUM["Deutsches_Hauptdreiecksnetz",
            SPHEROID["Bessel_1841",6377397.155,299.1528128]],
        PRIMEM["Greenwich",0],
        UNIT["Degree",0.017453292519943295]],
    PROJECTION["Cassini_Soldner"],
    PARAMETER["latitude_of_origin",52.41864827777778],
    PARAMETER["central_meridian",13.62720366666667],
    PARAMETER["false_easting",40000],
    PARAMETER["false_northing",10000],
    UNIT["Meter",1],
    PARAMETER["scale_factor",1.0]]
name: String (254.0)
notes: String (254.0)
admin_leve: String (254.0)
belongs_to: String (254.0)
belongs__1: String (254.0)
valid_sinc: Date (10.0)
valid_unti: Date (10.0)
OGRFeature(berlin_plz_segments):0
  name (String) = C,NW
  notes (String) = (null)
  admin_leve (String) = 3
  belongs_to (String) = 1101780000
  belongs__1 (String) = 1105580000
  valid_sinc (Date) = 1862/05/15
  valid_unti (Date) = 1873/07/24
  LINESTRING (24409 21404,24325.60068222816335 21373.160422727149125,24174.132778051218338 21358.822013509026874,24191 21148)

Note:

  • by chance, the first LINESTRING here is short
    • with other geometries the output can be much bigger

-- The original Spatialite SpatialTable used to create the Shape file looked like this: SpatialTable berlin_plz_segments

Note:

  • since Shapesfiles use the DBASE Database format
    • the field-names have been 'raped', due to the 8 Character field-name restriction
      • belongs_to_01 is now belongs_to
      • belongs_to_02 is now belongs__1

Later we will show a way how to import a shape-file

  • with the final table have usable, or if known the original, field-names

QGIS

  • to load a Shape-Files all you need to do is to

    • Drag and Drop the berlin_plz_segments.shp into QGIS
      • I believe, gdal (to which ogr is a part of) Drivers
        • are used with Drag and Drop as default
  • Select berlin_plz_segments : right-Mouse: select Open Attribute Table

    • will show the following QGIS Save AS
  • Select berlin_plz_segments : right-Mouse: select Propetries

    • select Fields
      • will show the following QGIS Save AS Shape

You can download the Shape file used in this sample here:


--> 'Using spatialite_gui for Shapefiles'


2014-07-22: Mark Johnson, Berlin Germany