Skip to content

GeoProcessor / Command / WriteGeoLayerToGeoJSON


Overview

The WriteGeoLayerToGeoJSON command writes a GeoLayer to a file in GeoJSON format, using RFC 7946 specification. The default format is minimalistic and is used with GeoProcessor automated tests.

  • The attributes of the GeoLayer are output as properties
  • The coordinate reference system defaults to EPSG:4326 (WGS84)
  • The coordinate maximum precision can be specified (extra zeros will be omitted)

In the future additional parameters will be added to further control output.

Command Editor

The following dialog is used to edit the command and illustrates the command syntax.

WriteGeoLayerToGeoJSON

WriteGeoLayerToGeoJSON Command Editor (see full-size image)

Command Syntax

The command syntax is as follows:

WriteGeoLayerToGeoJSON(Parameter="Value",...)

Command Parameters

Parameter                      Description Default          
GeoLayerID
required
The identifier of the GeoLayer to write. ${Property} syntax is recognized. None - must be specified.
OutputFile
required
The output GeoJSON file (relative or absolute path). ${Property} syntax is recognized. None - must be specified.
OutputCRS The coordinate reference system of the output GeoJSON. Always defaults to EPSG:4326 (WGS84) as per GeoJSON RFC-7946 specification.
OutputPrecision The maximum number of decimal points to include in the output GeoJSON file's coordinates. Must be a positive integer between 0 and 15.

The precision of coordinate values can greatly impact the size of the file and precision of drawing the features. For example, a higher OutputPrecision value increases the output GeoJSON file size and increases the geometry's precision. For further explanation, refer to the Precision section of the Decimal degrees Wikipedia page.
5

Examples

See the automated tests.

The following GeoLayer data are used in the examples. The examples assume that the ExampleGeoLayer1 and ExampleGeoLayer2 GeoLayers have already been read into the GeoProcessor with the ReadGeoLayerFromGeoJSON command.

Example GeoLayer Data

GeoLayerID Coordinate Reference System (CRS)
ExampleGeoLayer1 EPSG:4326 (WGS84)
ExampleGeoLayer2 EPSG:26913 (NAD83 UTM Zone 13N)

Example 1: Write a GeoLayer to a GeoJSON File

WriteGeoLayerToGeoJSON(GeoLayerID="ExampleGeoLayer1",OutputFile="ExampleOutputFolder/ExampleFile1")
WriteGeoLayerToGeoJSON(GeoLayerID="ExampleGeoLayer2",OutputFile="ExampleOutputFolder/ExampleFile2")

After running the commands, the following GeoJSON files are written to the ExampleOutputFolder folder.

ExampleOutputFolder

Filename File Type CRS Coordinate Precision
ExampleFile1.geojson GeoJSON EPSG:4326 (WGS84) 5
ExampleFile2.geojson GeoJSON EPSG:26913 (NAD83 UTM Zone 13N) 5

ExampleFile1_01.geojson File Content

{
"type":"FeatureCollection",
"features":[
{"type": "Feature", "properties": {"id":1},
"geometry":{"type": "Point", "coordinates": [ -1.3, 0.5]}}]
}

ExampleFile1_05.geojson File Content

{
"type":"FeatureCollection",
"features":[
{"type": "Feature", "properties": {"id":1},
"geometry":{"type": "Point", "coordinates": [ -1.33333, 0.52194]}}]
}

Troubleshooting

See Also