"loadShapeFile"

Loads an ESRI shape file.

Synopsis

bool loadShapeFile(string strFile, string strLayer[, string strOption1, string strOption2,...]);

Parameters

Parameter Description
strFile Specifies a shape file. The supported shape types are:
  • Point
  • PolyLine
  • Polygon
  • PointZ
  • PolyLineZ
  • PolygonZ
  • PointM
  • PolyLineM
  • PolygonM
strLayer Name of the layer the shape file will be loaded to.
strOption

The argument strOptions is needed when you have a layer that is being drawn in a background thread. Background drawing should be used when a layer is too big to be drawn in the foreground. Drawing in the background means that a thread that takes a longer time to draw the entire layer will be started.

The strOption is a combination of the following possible strings:

"THREAD"

Indicates that drawing will be done through a thread

"DISKBASED"

Indicates that drawing will be done through a thread and that shapes and database information will be read from disk directly (this means that they will not be pre-loaded into memory).

Diskbased drawing should only be used with static layers without texts.

Diskbased drawing is of course slower but will save a lot of ram memory.

("DISKBASED" means the same as combining the options "DISKBASEDSHAPES" and "DISKBASEDDATABASE").

"DISKBASEDSHAPES"

Indicates that drawing will be done through a thread and that shapes will be read from disk directly (means that they are not pre-loaded into memory).

Diskbased drawing should only be used with static layers without texts.

Diskbased drawing is of course slower but will save a lot of ram memory.

"DISKBASEDDATABASE"

Indicates that drawing will be done through a thread and that database information will be read from disk directly (means that they are not pre-loaded into memory).

Diskbased drawing should only be used with static layers without texts.

Diskbased drawing is of course slower but will save a lot of ram memory.

"FILLCOLOR=<color name>"

Specifies the color used to fill the polygons in a layer

"MINWIDTH=xx"

The minimum width of a layer.

"LINECOLOR=<color name>"

The line color of a layer.

"VISIBLE=0/1"

Make the layer visible or invisible

"FROM="

Specifies from which zoom factor the layer will be visible. This factor can be calculated with the current right and left position and the width of the GIS widget. You get the right and left position via getXRight() and getXLeft(). The width of the GIS widget is displayed in the GEDI.

The formula for the calculation is:

width of the widget / (XRight - XLeft) = zoom factor

Example:

right position = 20.4

left position = 8.4

width of the GIS widget = 714

714/ (20.4 - 8.4) = 59.5

"TO="

The zoom factor to which the layer will be visible.

Example:

right position = 15.8

left position = 11.7

width of the GIS widget = 714

714 / (15.8 - 11.7) = 174.15

Description

Loads an ESRI shape file, meaning three different files:

  • The actual shapes (".shp" file)

  • An index file (".shx" file). The shx is an index file that holds the byte position of each shape. It is used by the viewer when loading the individual shapes from the .shp file.

  • A DBF file (".dbf") holding information about each shape. Dbf is a DBase IV format database file. It contains information about each shape in the file. Typically it contains a ‘name’ for the shape, but it could contain any information field.

The GIS Viewer only uses the mandatory ".shp", ".shx" and ".dbf" files to draw a shape. ESRI shape files can contain additional data types, however, these files are not used by the GIS Viewer.

Save the maps in one of the subfolders of your project, for example, in the folder data/gis. Note hat you have to save all three different files in the directory in order to load the map.

You can find free ESRI shape files in the internet. See http://www.mapcruzin.com/download_mapcruz.htm or http://www.gfk-geomarketing.de/en/digital_maps/digital_map_samples/shape.html.

Diskbased drawing should only be used with static layers without texts. Various operations (e.g.: drawing texts, dynamic coloring of shapes) can only be used for shape files pre-loaded into the memory.

Example

This example loads several shape files and adds them as layers to the GIS Viewer EWO.

main()
{
  string strMap = "Gis/country";

  getPath(DATA_REL_PATH, strMap + ".shx");
//download file
  getPath(DATA_REL_PATH, strMap + ".shp");
//download file
  getPath(DATA_REL_PATH, strMap + ".dbf");
//download file

  this.loadShapeFile(getPath(DATA_REL_PATH) + strMap, "COUNTRY");

  strMap = "Gis/lakes";

  getPath(DATA_REL_PATH, strMap + ".shx");
//download file
  getPath(DATA_REL_PATH, strMap + ".shp");
//download file
  getPath(DATA_REL_PATH, strMap + ".dbf");
//download file

  this.loadShapeFile(getPath(DATA_REL_PATH) + strMap, "lakes");

  strMap = "Gis/rivers";

  getPath(DATA_REL_PATH, strMap + ".shx");
//download file
  getPath(DATA_REL_PATH, strMap + ".shp");
//download file
  getPath(DATA_REL_PATH, strMap + ".dbf");
//download file

  this.loadShapeFile(getPath(DATA_REL_PATH) + strMap, "rivers");

  strMap = "Gis/cities";

  getPath(DATA_REL_PATH, strMap + ".shx");
//download file
  getPath(DATA_REL_PATH, strMap + ".shp");
//download file
  getPath(DATA_REL_PATH, strMap + ".dbf");
//download file

  this.loadShapeFile(getPath(DATA_REL_PATH) + strMap, "cities");
}

The following example loads one shape file. The file will be loaded disk-based. It will possess the green fill color and black line color and be visible from 2 to 10 (the width is either degrees or meters depending on the map you use).

main()
{
  strMap = "Gis/country";

  getPath(DATA_REL_PATH, strMap + ".shx");
//download file
  getPath(DATA_REL_PATH, strMap + ".shp");
//download file
  getPath(DATA_REL_PATH, strMap + ".dbf");
//download file

  GisViewer_ewo1.loadShapeFile(getPath(DATA_REL_PATH) + strMap,
                               "COUNTRY",
                               "DISKBASED",
                               "FILLCOLOR=green",
                               "LINECOLOR=black",
                               "VISIBLE=1",
                               "FROM=2",
                               "TO=10");
}

Assignment

GIS Viewer