LuciadCPillar supports the decoding of GeoJSON data through the
GeoJsonModelDecoderGeoJsonModelDecoderGeoJsonModelDecoder.
The decoder supports RFC 7946 GeoJSON files and the legacy 2008 GeoJSON specification.
See the GeoJsonModelDecoderGeoJsonModelDecoderGeoJsonModelDecoder reference documentation
for the list of supported geometry types, file extensions, and limitations.
Visualizing GeoJSON data on a map requires these steps:
-
Decode the data into an
IFeatureModelIFeatureModelIFeatureModelusingGeoJsonModelDecoder::decode. -
Use a
FeatureLayerFeatureLayerFeatureLayerto visualize the model.
Decoding example
const auto model = GeoJsonModelDecoder::decode(path->string());
if (model.has_value()) {
// Use the feature model to create a FeatureLayer
} else {
std::cerr << "Could not decode GeoJSON: " << model.error().getMessage();
}
IFeatureModel featureModel = GeoJsonModelDecoder.Decode(resourcePath);
// Use the feature model to create a FeatureLayer
IFeatureModel featureModel = GeoJsonModelDecoder.decode(source);
// Use the feature model to create a FeatureLayer
Specifying a default coordinate reference
When a GeoJSON file contains no CRS declaration, LuciadCPillar defaults to WGS 84.
If your data uses a different coordinate reference system, supply a fallback through
GeoJsonModelDecoderOptionsGeoJsonModelDecoderOptionsGeoJsonModelDecoderOptions:
const auto defaultRef = *CoordinateReferenceProvider::create("EPSG:3857");
const auto options = GeoJsonModelDecoderOptions::newBuilder().defaultModelReference(defaultRef).build();
const auto model = GeoJsonModelDecoder::decode("data.geojson", options);
var defaultRef = CoordinateReferenceProvider.Create("EPSG:4326");
var options = GeoJsonModelDecoderOptions.NewBuilder()
.DefaultModelReference(defaultRef)
.Build();
IFeatureModel featureModel = GeoJsonModelDecoder.Decode(resourcePath, options);
CoordinateReference defaultRef = CoordinateReferenceProvider.create("EPSG:4326");
GeoJsonModelDecoderOptions options = GeoJsonModelDecoderOptions.newBuilder()
.defaultModelReference(defaultRef)
.build();
IFeatureModel featureModel = GeoJsonModelDecoder.decode(source, options);
Feature properties
The decoder turns each feature’s GeoJSON properties into DataPropertyDataPropertyDataProperty values on the model’s data type.
Scalar values become typed properties, JSON arrays become list properties, and nested JSON objects become
composite properties that you can read back as a DataObjectDataObjectDataObject.
A value that cannot be mapped to a typed property, such as an array of arrays, is preserved losslessly as a
string property that holds its raw JSON text. Such a property is tagged with a
JsonDataAnnotationJsonDataAnnotationJsonDataAnnotation, so you can tell it apart from an ordinary
string property and parse its value as JSON:
const DataType featureType = model->getFeatureModelMetadata().getDataModel().getDataTypes().front();
for (const DataProperty& property : featureType.getDataProperties()) {
if (JsonDataAnnotation::isPresent(property)) {
// 'property' holds raw JSON. Read its value from a feature as a string and parse it with your JSON library.
}
}
DataType featureType = featureModel.GetFeatureModelMetadata().DataModel.DataTypes[0];
foreach (DataProperty property in featureType.DataProperties)
{
if (JsonDataAnnotation.IsPresent(property))
{
// 'property' holds raw JSON. Read its value from a feature as a string and parse it with your JSON library.
}
}
DataType featureType = featureModel.getFeatureModelMetadata().getDataModel().getDataTypes().get(0);
for (DataProperty property : featureType.getDataProperties()) {
if (JsonDataAnnotation.isPresent(property)) {
// 'property' holds raw JSON. Read its value from a feature as a string and parse it with your JSON library.
}
}
The GeoJsonModelDecoderGeoJsonModelDecoderGeoJsonModelDecoder reference documentation describes the
full mapping. For how to read list and composite values from a feature, see
Describing a feature structure with a data model.
See Visualizing Feature Data for more information about visualizing and styling vector data.