ido flax
ido flax

Reputation: 528

GeoTools no such attribute error when parsing GeoJson

According to the GeoJson spec (https://www.rfc-editor.org/rfc/rfc7946), features with different sets of properties are allowed, but when i am processing my GeoJson file using FeatureJSON.readFeatureCollection i get an error saying no such attribute:tract_boundary.

here's the part of my file showing the two features with different properties (notice the attribute name "tract_boundary" appears in the second feature properties):

{
      "type": "Feature",
      "properties": {
        "clu_identifier": "3ecc54fc-5077-11d6-8e82-00065b4a19c0",
        "clu_alt_id": "{5626C60F-23B1-4172-BCFA-842EBDEE776F}",
        "data_source": "danna.steffens",
        "clu_status": null,
        "tract_number": "768",
        "last_change_date": 1352656579000,
        "last_chg_user_nm": null,
        "creation_date": 1113921633000,
        "admin_state": "20",
        "clu_calculated_acreage": 152.41,
        "OBJECTID": 582,
        "cropland_indicator_3CM": 1,
        "edit_reason": null,
        "GlobalId": "{DE7A11AA-BFB6-4DFE-A1D7-D795D7DD7990}",
        "SHAPE_STArea__": 1012852.6422872,
        "state_code": "20",
        "cdist_fips": "2001",
        "highly_erodible_land_type_code": "NHEL",
        "admin_county": "171",
        "clu_classification_code": "2",
        "sap_crp": null,
        "farm_number": "4384",
        "SHAPE_STLength__": 4161.19756459,
        "ESRI_OID": 530,
        "clu_number": "1",
        "data_source_site_identifier": null,
        "comments": " ",
        "county_code": "171"
      },
      "geometry": {...
},
{
      "type": "Feature",
      "properties": {
        "farm_number": "4384",
        "admin_state": "20",
        "tract_number": "5468",
        "admin_county": "171",
        "tract_boundary": true
      },
      "geometry": {...
}

Any ideas?

Upvotes: 1

Views: 733

Answers (2)

NY_208
NY_208

Reputation: 1

Your features' properties have to be proper subset of the first feature, or it will throw this exception. But I'm still working on finding out the solution for it.

Upvotes: 0

Ian Turton
Ian Turton

Reputation: 10976

You can get the "full" schema by calling org.geotools.geojson.feature.FeatureJSON.readFeatureCollectionSchema(Object, boolean) with the 2nd argument set to false so that the whole collection is read rather than just the first item. Then you can set the FeatureType of your features correctly.

Upvotes: 1

Related Questions