|
LuciadCPillar C# 2026.1.02
|
This class can be used to decode GeoJSON data into an IFeatureModel.
More...
Static Public Member Functions | |
| static Luciad.Models.Features.IFeatureModel | Decode (string source) |
| Creates a GeoJSON feature model, or returns information about why this model cannot be created. | |
| static Luciad.Models.Features.IFeatureModel | Decode (string source, Luciad.Formats.Geojson.GeoJsonModelDecoderOptions options) |
| Creates a GeoJSON feature model, or returns information about why this model cannot be created. | |
This class can be used to decode GeoJSON data into an IFeatureModel.
Supports RFC 7946 GeoJSON and the legacy 2008 GeoJSON specification for CRS handling.
| Extension | Description |
|---|---|
| *.geojson | GeoJSON file |
| *.json | GeoJSON or other JSON |
| *.js | GeoJSON as JavaScript |
| Root type | Result |
|---|---|
| FeatureCollection | All features decoded |
Feature | Single-feature collection |
Geometry type | Feature collection with one synthetic Feature |
| GeoJSON geometry type | CPillar geometry |
|---|---|
Point | Point |
| MultiPoint | MultiGeometry of Points |
| LineString | Polyline |
| MultiLineString | MultiGeometry of Polylines |
Polygon | Polygon (exterior ring + optional holes) |
| MultiPolygon | MultiGeometry of Polygons |
| GeometryCollection | MultiGeometry (heterogeneous, recursive) |
| missing | Feature without geometry |
Each JSON property value is decoded into a DataProperty, with a type that is inferred from the value:
| JSON property value | Decoded as |
|---|---|
| String | a string property |
| Integer number | a long property |
| Fractional number | a double property |
| Boolean | a boolean property |
| null | the property is left unset for that feature |
| Array of primitive values | a list property, with an element type inferred like a scalar |
| Array of objects | a list property with an element type is a composite |
| Object | a composite property with a type that mirrors the object |
The feature DataType is the union of the properties seen across all features. The rest of this section covers how the decoder combines a property's values across features, and what it does with a value that it cannot model as a typed property.
When a property holds different value types in different features, they are combined into a single type. The same rule combines a list's element type, both within a single array and across features. A null is ignored while combining, and a null array element is kept as an empty entry so element positions are preserved.
| Values seen for a property | Combined type |
|---|---|
| 42 then "high" | string |
| 1 (integer) then 1.5 (fractional) | double |
| a boolean then a number | string |
| list [1] then list [1.5] | double list |
| [1, "two", true] in one array | string list |
Combining applies only while the value keeps the same shape: scalar, list, or composite object.
A value that fits no typed property is preserved losslessly as a string property holding its raw JSON text, tagged with JsonDataAnnotation so a consumer can tell it apart from a plain string:
| Value the decoder cannot model | Example |
|---|---|
| incompatible shapes in different features | 42 in one feature, {"nested": 1} in another |
| a list mixing primitive and object elements | [1, 2] in one feature, [{"a": 1}] in another |
| an array with elements that are themselves arrays | [[1, 2], [3, 4]] |
| a list empty or all-null in every feature | [] in every feature |
| an object with no modelable members | {}, or members that are all null |
A property that is null in every feature carries no value and is left out of the schema entirely. This differs from the empty-list case above, which is preserved as raw JSON.
A property with a value that is a JSON object becomes a composite property. The decoder infers a nested DataType from the object's members, unioned across features and applied recursively to objects within objects. Each nested type is named after the path that leads to it, joining the feature type name and the field names with underscores: an "address" object yields Feature_address, and a "location" object nested inside it yields Feature_address_location. An array of objects becomes a list property of which the element type is that composite, built with the same naming and recursion. The raw-JSON fallback applies per member, so a modelable member stays typed while an unmodelable sibling beside it is preserved as raw JSON.
A top-level id member becomes a string property named "id". A property named "geometry" is skipped because it conflicts with the reserved geometry property.
When no legacy "crs" member is present, the decoder falls back to a user-supplied default model reference, which you can set through GeoJsonModelDecoderOptions.Builder.DefaultModelReference. If none is set, the decoder falls back to WGS 84 (EPSG:4326 for 2D data, EPSG:4979 for 3D data). When a legacy "crs" member is present, its named CRS identifier is resolved through CoordinateReferenceProvider, and any user-supplied default is ignored.
GeoJsonModelDecoder.Decode for more details.
|
inlinestatic |
Creates a GeoJSON feature model, or returns information about why this model cannot be created.
This is a convenience overload equivalent to calling decode(source, GeoJsonModelDecoderOptions.newBuilder().build()).
| source | The path, URL, or logical identifier for the GeoJSON data. |
| System.IO.IOException | when creation of the model fails. |
| System.NotSupportedException | when the source cannot be handled (for example, an unsupported scheme or root type). |
|
inlinestatic |
Creates a GeoJSON feature model, or returns information about why this model cannot be created.
When the GeoJsonModelDecoderOptions contain a dataLoader, the decoder first attempts to resolve the source string through that loader. If the loader returns ErrorCode.Unsupported, the decoder falls back to file-based or URL-based loading. All other loader errors are propagated.
| source | The path, URL, or logical identifier for the GeoJSON data. |
| options | Options controlling how the source is resolved. |
| System.IO.IOException | when creation of the model fails. |
| System.NotSupportedException | when the source cannot be handled (for example, an unsupported scheme or root type). |