4

At the following URL there is a FeatureCollection of US Counties.

I have tried saving the FeatureCollection as a json file with:

curl "https://bubinga.co/wp-content/uploads/jsoncounties.min_.js" -o "counties.json"

But in QGIS the file does not display:

enter image description here

I have also tried importing into QGIS directly with:

enter image description here

But the same problem occurs. I am sure I am missing something simple - what could be the issue?

enter image description here

EDIT:

The 10.5 MB file is valid JSON according to jsonlint.com and begins as:

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"state":"AL","counties":67},"counties":[{"name":"Autauga","geographicRegion":"Autauga County, Alabama","geometry":{"type":"Polygon","coordinates":[[[-86.41182,32.4757],[-86.41177,32.46599],[-86.41167,32.45054],[-86.41157,32.44245],[-86.41154,32.43993],[-86.41138,32.42573],[-86.41135,32.42417],[-86.41128,32.42185],[-86.41117,32.41017],[-86.41117,32.40994],[-86.41615,32.4072],[-86.43178,32.40132],[-86.43926,32.40025],[-86.44653,32.40036],[-86.45876,32.40573],[-86.4612,32.40285],[-86.46247,32.38769],[-86.46356,32.37729],[-86.46836,32.37368],[-86.47092,32.37136],[-86.47306,32.36874],[-86.47476,32.36588],[-86.47777,32.36418],[-86.48023,32.36497],[-86.48342,32.36667],[-86.4871,32.36674],[-86.49047,32.36532],[-86.49265,32.36286],[-86.49263,32.36032],[-86.49181,32.35787],[-86.4908,32.35513],[-86.48994,32.35264],[-86.4899,32.34985],[-86.49071,32.34705],[-86.49308,32.34509],[-86.49637,32.34451],[-86.49677,32.34444],[-86.49697,32.34441],[-86.51978,32.34039],[-86.54242,32.36286],[-86.56658,32.37296],[-86.58826,32.36775],[-86.61646,32.38072],[-86.61548,32.40307],[-86.62671,32.40372],[-86.64956,32.40055],[-86.65426,32.37904],[-86.66333,32.36937],[-86.67726,32.35659],[-86.68276,32.35356],[-86.69448,32.35677],[-86.71309,32.36186],[-86.71624,32.36921],[-86.71982,32.3884],[-86.71721,32.40129],[-86.73083,32.40061],[-86.75543,32.38914],[-86.78214,32.39047],[-86.78238,32.37337],[-86.7843,32.32449],[-86.80352,32.30819],[-86.82039,32.3184],[-86.81563,32.3402],[-86.81491,32.3408],[-86.81229,32.34299],[-86.81294,32.36582],[-86.8318,32.38605],[-86.8411,32.41849],[-86.83652,32.4304],[-86.85357,32.43893],[-86.86242,32.43869],[-86.86415,32.44592],[-86.86997,32.4606],[-86.87364,32.47188],[-86.88497,32.48191],[-86.88087,32.48886],[-86.88465,32.49656],[-86.89084,32.5124],[-86.89979,32.52588],[-86.90667,32.53685],[-86.90521,32.54915],[-86.90023,32.55933],[-86.89905,32.57819],[-86.90385,32.59242],[-86.90759,32.60835],[-86.91163,32.62085],[-86.9119,32.63178],[-86.9185,32.64452],[-86.91827,32.65322],[-86.91767,32.66411],[-86.91759,32.66417],[-86.91757,32.66417],[-86.91241,32.66425],[-86.8929,32.66343],[-86.87358,32.66258],[-86.84557,32.66137],[-86.83382,32.66082],[-86.81764,32.66016],[-86.81319,32.66017],[-86.78767,32.66052],[-86.74998,32.66098],[-86.72508,32.66159],[-86.71349,32.66738],[-86.71257,32.70574],[-86.66704,32.70609],[-86.63189,32.70633],[-86.61778,32.70629],[-86.60783,32.70632],[-86.59515,32.70653],[-86.57015,32.70678],[-86.52944,32.70704],[-86.4963,32.7073],[-86.48468,32.7076],[-86.47197,32.70778],[-86.46803,32.70786],[-86.45035,32.70809],[-86.41583,32.70747],[-86.41312,32.70739],[-86.413,32.67818],[-86.41298,32.67406],[-86.41261,32.61636],[-86.4125,32.58942],[-86.41244,32.57816],[-86.41234,32.55023],[-86.41226,32.53344],[-86.41223,32.52876],[-86.4122,32.52668],[-86.4123,32.52082],[-86.41231,32.51273],[-86.41234,32.50446],[-86.4122,32.50006],[-86.41212,32.49626],[-86.41197,32.49065],[-86.41197,32.48577],[-86.41187,32.48112]]]}},

  • 1
    Please add a snippet of the file to the question – Ian Turton Jan 25 '17 at 18:08
  • You can just click on the link. Added – the_darkside Jan 25 '17 at 18:20
  • 1
    It's quite a big file at 10.5MB, so guess that might be an issue on your system. It is valid JSON according to jsonlint.com. – nmtoken Jan 25 '17 at 19:57
  • What do you get when you paste it into geojsonlint.com ? – RyanDalton Jan 25 '17 at 23:31
  • If I recall, correctly, QGIS may need a variable declared in the GeoJSON file. Try adding "var counties = " at the head of the JSON text within the file. – RyanDalton Jan 25 '17 at 23:55
4

I see the same thing (QGIS 2.18.3)

It's all on one line, so I pretty-printed using python 3.5 at the command line...

python3.5 -m json.tool ./counties.geojson | less

here's what the first few lines look like when pretty-printed

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "state": "AL",
                "counties": 67
            },
            "counties": [
                {
                    "name": "Autauga",
                    "geographicRegion": "Autauga County, Alabama",
                    "geometry": {
                        "type": "Polygon",
                        "coordinates": [
                            [

That's certainly valid JSON. Not sure if it's valid GeoJSON, though. I think the geojson spec was updated fairly recently so it might be worth checking that.

I think it's the structure being nested too deep, each state is a feature, and counties are sub-features (?). I think the json may need to be restructured so that each county is a feature in its own right. In other words, i think the "geometry" should be a sibling of "properties"

That's just a gut feel, but it should be possible in Python/JavaScript to rewrite a new geojson file, by removing the state/county hierarchy, and promoting each county to a feature.

4

This JSON file is not a valid GeoJSON. It is a FeatureCollection with 56 Features, but 3251 geometries

A valid GeoJSON Feature format is (with 1 geometry for 1 feature and the fundamental keys/tags 'geometry' and 'properties')

{
"type": "Feature",
"geometry":{
 .....
},
"properties": {
....
}
}

The Feature format of counties.json is not a valid GeoJSON format (no 'geometry' tag/key but a list of geometries for 1 feature in 'counties').

{
"type": "Feature",
"counties": {
    [list of geometries]
},
"properties": {
     ....
}
}

Explanation

Opening the file with Python

import json
filename = "counties.json"
def load_json(filename):
    with open(filename, 'r') as f:
         return json.load(f)
geo = load_json(filename)

geo is now a Python dictionary with 56 features (len(geo['features']))

If we examine the first feature

first = geo['features'][0]
print first.keys()
[u'type', u'properties', u'counties']
print first['type']
Feature

There is no tag/key 'geometry' therefore the Feature is not valid.

The geometries are in the 'counties' tag/key

print len(first['counties'])
67
# tags/keys of the first county
print first['counties'][0].keys()
[u'geometry', u'geographicRegion', u'name']

With this JSON file, valid GeoJSON Features would be

print first['counties'][0]['geographicRegion'] 
Saipan Municipality, Mariana Islands
feature=dict(type='Feature', properties = first['properties'],geometry=first['counties'][0]['geometry'])

enter image description here

print first['counties'][1]['geographicRegion']
Tinian Municipality, Mariana Islands
feature=dict(type='Feature', properties = first['properties'],geometry=first['counties'][1]['geometry'])

enter image description here

etc...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.