-
Notifications
You must be signed in to change notification settings - Fork 1
ESRI Shapefile
ESRI Shapefiles are used to store vector data and related attribute data.
The ESRI Shapefile format always consists of (at least) three accompanying files, with the extensions:
- .shp: containing the geographical coordinates(feature attribute).
- .shx: containing a spatial index.
- .dbf: containing tabular information describing the shapes. If a logical entity (like countries) consists of multiple shapes, the relation between the shapes and the logical entity is usually stored in this .dbf file.
Optionally a .prj file is als available, containing the projection information. This file is at the moment not (yet) used by the GeoDMS (projection information is configured explicitly in the GeoDMS).
The GeoDMS supports at the moment (multi)point, arc and polygon types (Shape types: 1,3, 5 and 8).
The GeoDMS supports two ways of reading ESRI Shapefiles:
- gdal.vect: for most shape files, we advice to use gdal.vect (see next subparagraph) to read csv files as it:
- is faster
- is more generic
- is shorter to configure
- supports open options
- supports segmented data (If the file has more than 50.000 records, tiled domain with segments of maximum 50.000 entries will be made)
- shapefile/dbf StorageManager
how to configure reading point, polygon and arc data with gdal.vect:
unit<uint32> location
: StorageName = "%projDir%/vectordata/points.shp"
, StorageType = "gdal.vect"
{
attribute<point_rd> geometry;
attribute<string> name;
}
unit<uint32> region
: StorageName = "%projDir%/vectordata/region.shp"
, StorageType = "gdal.vect"
{
attribute<point_rd> geometry (polygon);
attribute<string> name;
}
unit<uint32> road
: StorageName = "%projDir%/vectordata/road.shp"
, StorageType = "gdal.vect"
{
attribute<point_rd> geometry (arc);
attribute<string> name;
}
The .shp file is configured as StorageName for the domain unit.
The .dbf and .shx files are not explicitly configured, but need to be available in the same folder as the .shp file.
The difference between the configuration of points, arcs and polygons is the configured composition type.
If your dbf file already contains an attribute named geometry, use another attribute name for the data from the .shp file, for instance geom.
GDAL options can be configured for reading different ESRI Shapefiles.
See: https://gdal.org/drivers/vector/shapefile.html#vector-shapefile for a full list of all open options.
Shapefiles can also still be read from or written to with the GeoDMS specific shapefile/dbf StorageManagers (mainly for backward compatibility).
how to configure reading point, polygon and arc data with shapefile/dbf StorageManager:
unit<uint32> location: StorageName = "%projDir%/data/location.dbf"
{
attribute<point_rd> geometry: StorageName = "%projDir%/data/location.shp";
attribute<string> name;
}
unit<uint32> region: StorageName = "%projDir%/data/region.dbf"
{
attribute<point_rd> region (polygon): StorageName = "%projDir%/data/region.shp";
attribute<string> name;
}
unit<uint32> road: StorageName = "%projDir%/data/road.dbf"
{
attribute<point_rd> geometry (arc): StorageName = "%projDir%/data/road.shp";
attribute<string> name;
}
The dbf file is configured as StorageName of the domain unit. The number of elements is read from this file.
The feature attribute with the coordinates is configured as subitem of the domain unit. This attribute is read from or written to the explicitly configured .shp file. The .shx file is not configured, the file needs to be available in the same folder as the .shp file.
The difference between the configuration of points, arcs and polygons is the configured composition type.
The GeoDMS supports two ways of writing ESRI Shapefiles:
- gdalwrite.vect: for most shape files, we advice to use gdalwrite.vect (see next subparagraph) to write csv files as it:
- is faster
- is more generic
- is shorter to configure
- supports open options
- shapefile/dbf StorageManager
The following example shows how to write an ESRI Shapefile with the gdalwrite.vect StorageManager.
unit <uint32> pc6_export := src/pc6
, StorageName = "%localDataProjDir%/export_semicolon.csv"
, StorageType = "gdalwrite.vect"
, StorageReadOnly = "false"
{
attribute<uint32> IntegerAtt := const(1, .);
attribute<float32> FloatAtt := const(1f, .);
attribute<string> StringAtt := const('A', .);
attribute<bool> BoolAtt := const(true, .);
}
Attributes of all value types, except for values types of the point group, are written to a csv file. This applies to both the direct as the indirect subitems.
The resulting file will contain one header line with the name of each attribute. By default a semicolon is used as seperator and all attributes will be double quoted.
GDAL Options can be configured for writing different csv files.
See: https://gdal.org/drivers/vector/csv.html?highlight=csv for a full list of all creation options.
Examples on how to configure write options:
container comma
{
unit<uint32> optionSet := range(uint32, 0, 1);
attribute<string> GDAL_LayerCreationOptions (optionSet) : ["SEPARATOR=COMMA"];
uni< pc6_export := src/pc6
, StorageName = "%localDataProjDir%/export_comma.csv"
, StorageType = "gdalwrite.vect"
, StorageReadOnly = "false"
{
attribute<uint32> IntegerAtt := const(1, .);
attribute<float32> FloatAtt := const(1f, .);
attribute<string> StringAtt := const('A', .);
attribute<bool> BoolAtt := const(true, .);
}
}
container geometry_as_wkt
{
unit<uint32> optionSet := range(uint32, 0, 3);
attribute<string> GDAL_LayerCreationOptions (optionSet) :
["GEOMETRY=AS_WKT", "GEOMETRY_NAME=GEOMETRY", "CREATE_CSVT=YES"];
unit<uint32> poly := EsriShape/Polygon
, StorageName = "%localDataProjDir%/poly.csv"
, StorageType = "gdalwrite.vect"`
, StorageReadOnly = "false"`
{
attribute<fpoint> geometry (poly) := EsriShape/Polygon/Geometry;
attribute<string> label := EsriShape/Polygon/Label;
}
}
The first example show how to configure a csv file with a comma as separator.
The second example shows how you can also write a vector geometry to a csv file (point, line and polygon). The data will be written als well-known textformat (WKT).
The second option in this examples configures the name in the csv file with the WKT. The third option indicates that a .csvt is also written with exported attribute names.
We advice to use different containers for configuring csv files with different creation options.
GeoDMS ©Object Vision BV. Source code distributed under GNU GPL-3. Documentation distributed under CC BY-SA 4.0.