5

I have geoJson from the the USGS that I am downloading to my server.

It validates just fine with geojsonlint.

When I past the JSON into this Openlayers example it says it is bad input json.

My Code to display it on a vector layer is as follows where variable mapProjection is EPSG:900913.

I have spent 3 days on this now, and cannot get it do display. What am I doing wrong?

Added Information, I have tried this method:

vectorLayer = new OpenLayers.Layer.Vector("MyLayer");
map.addLayer(vectorLayer);

function handler(request) {

var geojson_format = new OpenLayers.Format.GeoJSON({
    'internalProjection': map.baseLayer.projection,
    'externalProjection': new OpenLayers.Projection("EPSG:4326")
});

vectorLayer.addFeatures(geojson_format.read(request.responseText));
}

var request = OpenLayers.Request.GET({
    url: "geojson.json",
    callback: handler
});

and have been able to see the json in variable request in the handler function. It has to be something to do with the format of the data.

I am on a windows system and writing the data to a txt file, then serving it to my openlayers app via IIS. I have the correct mime types set up for json already.

    var geojson_format = new OpenLayers.Format.GeoJSON({
                'internalProjection': mapProjection,
                'externalProjection': wgs84
                });

var newlayer = new OpenLayers.Layer.Vector(
            layername, 
            {
            style: style_mark,
            projection: wgs84,                          
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP
                    ({
                            url: '/data/earthquake_day.json?' + forcedownload,
                            format: geojson_format
                    })
            }
    );
 map.addLayers([newlayer]);

This is the Geojson ..

{"type":"FeatureCollection","metadata":{"generated":1382079580000,"url":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson?%2053324","title":"USGS Magnitude 2.5+ Earthquakes, Past Day","status":200,"api":"1.0.11","count":21},"features":[{"type":"Feature","properties":{"mag":4.9,"place":"69km WSW of Panguna, Papua New Guinea","time":1382072700910,"updated":1382074535000,"tz":600,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kg7b","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kg7b.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":369,"net":"us","code":"b000kg7b","ids":",usb000kg7b,","sources":",us,","types":",cap,general-link,geoserve,nearby-cities,origin,phase-data,tectonic-summary,","nst":null,"dmin":8.182,"rms":0.95,"gap":86,"magType":"mb","type":"earthquake","title":"M 4.9 - 69km WSW of Panguna, Papua New Guinea"},"geometry":{"type":"Point","coordinates":[154.9386,-6.6267,38.4]},"id":"usb000kg7b"},
{"type":"Feature","properties":{"mag":4.3,"place":"30km ESE of Jarm, Afghanistan","time":1382069641720,"updated":1382071013039,"tz":270,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kg6q","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kg6q.geojson","felt":0,"cdi":1,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":284,"net":"us","code":"b000kg6q","ids":",usb000kg6q,","sources":",us,","types":",cap,dyfi,general-link,geoserve,nearby-cities,origin,phase-data,tectonic-summary,","nst":null,"dmin":2.372,"rms":0.49,"gap":112,"magType":"mb","type":"earthquake","title":"M 4.3 - 30km ESE of Jarm, Afghanistan"},"geometry":{"type":"Point","coordinates":[71.1215,36.7111,215.63]},"id":"usb000kg6q"},
{"type":"Feature","properties":{"mag":4.4,"place":"37km ESE of Grande Anse, Guadeloupe","time":1382068917150,"updated":1382075936219,"tz":-240,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kg6l","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kg6l.geojson","felt":1,"cdi":2,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":298,"net":"us","code":"b000kg6l","ids":",usb000kg6l,","sources":",us,","types":",cap,dyfi,geoserve,nearby-cities,origin,phase-data,tectonic-summary,","nst":null,"dmin":0.927,"rms":1.03,"gap":187,"magType":"mb","type":"earthquake","title":"M 4.4 - 37km ESE of Grande Anse, Guadeloupe"},"geometry":{"type":"Point","coordinates":[-60.7685,16.1425,44.69]},"id":"usb000kg6l"},
{"type":"Feature","properties":{"mag":4.8,"place":"59km ENE of Raoul Island, New Zealand","time":1382060352340,"updated":1382062761000,"tz":-720,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kg5r","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kg5r.geojson","felt":0,"cdi":1,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":354,"net":"us","code":"b000kg5r","ids":",usb000kg5r,","sources":",us,","types":",cap,dyfi,general-link,geoserve,nearby-cities,origin,phase-data,tectonic-summary,","nst":null,"dmin":0.547,"rms":1.24,"gap":109,"magType":"mb","type":"earthquake","title":"M 4.8 - 59km ENE of Raoul Island, New Zealand"},"geometry":{"type":"Point","coordinates":[-177.3712,-28.9952,68.09]},"id":"usb000kg5r"},
{"type":"Feature","properties":{"mag":4.6,"place":"65km WSW of Manta, Ecuador","time":1382059956670,"updated":1382063766330,"tz":-300,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kg5p","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kg5p.geojson","felt":3,"cdi":3.4,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":327,"net":"us","code":"b000kg5p","ids":",usb000kg5p,","sources":",us,","types":",cap,dyfi,general-link,geoserve,nearby-cities,origin,phase-data,tectonic-summary,","nst":null,"dmin":3.14,"rms":0.76,"gap":105,"magType":"mb","type":"earthquake","title":"M 4.6 - 65km WSW of Manta, Ecuador"},"geometry":{"type":"Point","coordinates":[-81.3056,-1.0801,25.2]},"id":"usb000kg5p"},
{"type":"Feature","properties":{"mag":4.9,"place":"Central Mid-Atlantic Ridge","time":1382059845140,"updated":1382060754000,"tz":-180,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kg5q","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kg5q.geojson","felt":0,"cdi":1,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":369,"net":"us","code":"b000kg5q","ids":",usb000kg5q,","sources":",us,","types":",cap,dyfi,general-link,geoserve,nearby-cities,origin,phase-data,","nst":null,"dmin":13.904,"rms":1.17,"gap":79,"magType":"mb","type":"earthquake","title":"M 4.9 - Central Mid-Atlantic Ridge"},"geometry":{"type":"Point","coordinates":[-38.5333,7.9178,10]},"id":"usb000kg5q"},
{"type":"Feature","properties":{"mag":3.1,"place":"114km N of San Juan, Puerto Rico","time":1382057000700,"updated":1382075958596,"tz":-240,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/pr13291001","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/pr13291001.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"REVIEWED","tsunami":null,"sig":148,"net":"pr","code":"13291001","ids":",pr13291001,","sources":",pr,","types":",cap,geoserve,nearby-cities,origin,tectonic-summary,","nst":4,"dmin":1.23159025,"rms":0.21,"gap":306,"magType":"Md","type":"earthquake","title":"M 3.1 - 114km N of San Juan, Puerto Rico"},"geometry":{"type":"Point","coordinates":[-66.0585,19.4955,15]},"id":"pr13291001"},
{"type":"Feature","properties":{"mag":3.2,"place":"153km NNE of Vieques, Puerto Rico","time":1382056681300,"updated":1382074489829,"tz":-240,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/pr13291000","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/pr13291000.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"REVIEWED","tsunami":null,"sig":158,"net":"pr","code":"13291000","ids":",pr13291000,","sources":",pr,","types":",cap,geoserve,nearby-cities,origin,tectonic-summary,","nst":6,"dmin":1.39957521,"rms":0.28,"gap":309.6,"magType":"Md","type":"earthquake","title":"M 3.2 - 153km NNE of Vieques, Puerto Rico"},"geometry":{"type":"Point","coordinates":[-65.3018,19.7154,18]},"id":"pr13291000"},
{"type":"Feature","properties":{"mag":2.9,"place":"61km NE of Camalu, Mexico","time":1382048867000,"updated":1382051103563,"tz":-420,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/ci11379962","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ci11379962.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"REVIEWED","tsunami":null,"sig":129,"net":"ci","code":"11379962","ids":",ci11379962,","sources":",ci,","types":",cap,general-link,geoserve,nearby-cities,origin,scitech-link,tectonic-summary,","nst":3,"dmin":0.24254513,"rms":0.14,"gap":194.4,"magType":"Ml","type":"earthquake","title":"M 2.9 - 61km NE of Camalu, Mexico"},"geometry":{"type":"Point","coordinates":[-115.6183,31.2453,6]},"id":"ci11379962"},
{"type":"Feature","properties":{"mag":2.9,"place":"26km NE of Soledad, California","time":1382048604900,"updated":1382061371165,"tz":-420,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/nc72089726","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72089726.geojson","felt":1,"cdi":1,"mmi":null,"alert":null,"status":"AUTOMATIC","tsunami":null,"sig":129,"net":"nc","code":"72089726","ids":",nc72089726,","sources":",nc,","types":",dyfi,focal-mechanism,general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,tectonic-summary,","nst":null,"dmin":0.04491576,"rms":0.14,"gap":43.2,"magType":"Md","type":"earthquake","title":"M 2.9 - 26km NE of Soledad, California"},"geometry":{"type":"Point","coordinates":[-121.1617,36.6223,7.9]},"id":"nc72089726"},
{"type":"Feature","properties":{"mag":4.9,"place":"Mid-Indian Ridge","time":1382040756270,"updated":1382069714445,"tz":300,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kfvj","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kfvj.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":369,"net":"us","code":"b000kfvj","ids":",usb000kfvj,","sources":",us,","types":",cap,dyfi,geoserve,nearby-cities,origin,phase-data,","nst":null,"dmin":20.785,"rms":0.71,"gap":74,"magType":"mb","type":"earthquake","title":"M 4.9 - Mid-Indian Ridge"},"geometry":{"type":"Point","coordinates":[69.0736,-23.117,10]},"id":"usb000kfvj"},
{"type":"Feature","properties":{"mag":3.2,"place":"26km ESE of Cohoe, Alaska","time":1382037828000,"updated":1382066784427,"tz":-480,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/ak10825881","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ak10825881.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"AUTOMATIC","tsunami":null,"sig":158,"net":"ak","code":"10825881","ids":",ak10825881,","sources":",ak,","types":",dyfi,general-link,geoserve,nearby-cities,origin,tectonic-summary,","nst":67,"dmin":0.40963177,"rms":0.68,"gap":72,"magType":"Ml","type":"earthquake","title":"M 3.2 - 26km ESE of Cohoe, Alaska"},"geometry":{"type":"Point","coordinates":[-150.8756,60.258,64.3]},"id":"ak10825881"},
{"type":"Feature","properties":{"mag":4.9,"place":"176km ENE of Hachinohe, Japan","time":1382028863680,"updated":1382057818725,"tz":600,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kfnh","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kfnh.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":369,"net":"us","code":"b000kfnh","ids":",usb000kfnh,","sources":",us,","types":",cap,dyfi,general-link,geoserve,nearby-cities,origin,phase-data,tectonic-summary,","nst":null,"dmin":1.191,"rms":1.37,"gap":175,"magType":"mb","type":"earthquake","title":"M 4.9 - 176km ENE of Hachinohe, Japan"},"geometry":{"type":"Point","coordinates":[143.529,40.8559,31.69]},"id":"usb000kfnh"},
{"type":"Feature","properties":{"mag":3.1,"place":"33km N of Fritz Creek, Alaska","time":1382027563000,"updated":1382056509941,"tz":-480,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/ak10825772","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ak10825772.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"AUTOMATIC","tsunami":null,"sig":148,"net":"ak","code":"10825772","ids":",ak10825772,","sources":",ak,","types":",dyfi,general-link,geoserve,nearby-cities,origin,tectonic-summary,","nst":69,"dmin":0.31351203,"rms":0.87,"gap":86.4,"magType":"Ml","type":"earthquake","title":"M 3.1 - 33km N of Fritz Creek, Alaska"},"geometry":{"type":"Point","coordinates":[-151.1942,60.0298,87.9]},"id":"ak10825772"},
{"type":"Feature","properties":{"mag":3.6,"place":"14km ESE of Hyrum, Utah","time":1382026759900,"updated":1382079018263,"tz":-360,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/uu60041537","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/uu60041537.geojson","felt":190,"cdi":3.2,"mmi":3.25,"alert":null,"status":"REVIEWED","tsunami":null,"sig":260,"net":"uu","code":"60041537","ids":",uu60041537,","sources":",uu,","types":",cap,dyfi,general-link,geoserve,nearby-cities,origin,shakemap,tectonic-summary,","nst":null,"dmin":0.07186522,"rms":0.14,"gap":57.6,"magType":"Ml","type":"earthquake","title":"M 3.6 - 14km ESE of Hyrum, Utah"},"geometry":{"type":"Point","coordinates":[-111.6838,41.6033,11.4]},"id":"uu60041537"},
{"type":"Feature","properties":{"mag":2.7,"place":"10km WNW of Shasta Lake, California","time":1382024460700,"updated":1382058287850,"tz":-420,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/nc72089531","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72089531.geojson","felt":1,"cdi":2,"mmi":null,"alert":null,"status":"AUTOMATIC","tsunami":null,"sig":112,"net":"nc","code":"72089531","ids":",nc72089531,","sources":",nc,","types":",dyfi,general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,","nst":null,"dmin":0.06288207,"rms":0.13,"gap":90,"magType":"Ml","type":"earthquake","title":"M 2.7 - 10km WNW of Shasta Lake, California"},"geometry":{"type":"Point","coordinates":[-122.4883,40.7127,22.4]},"id":"nc72089531"},
{"type":"Feature","properties":{"mag":2.6,"place":"13km SSE of Volcano, Hawaii","time":1382022033300,"updated":1382022379514,"tz":-600,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/hv60578296","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/hv60578296.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"AUTOMATIC","tsunami":null,"sig":104,"net":"hv","code":"60578296","ids":",hv60578296,","sources":",hv,","types":",general-link,geoserve,nearby-cities,origin,","nst":null,"dmin":0.05389892,"rms":0.35,"gap":100.8,"magType":"Ml","type":"earthquake","title":"M 2.6 - 13km SSE of Volcano, Hawaii"},"geometry":{"type":"Point","coordinates":[-155.1912,19.3207,1.8]},"id":"hv60578296"},
{"type":"Feature","properties":{"mag":2.5,"place":"8km SSW of Volcano, Hawaii","time":1382019528300,"updated":1382055396752,"tz":-600,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/hv60578286","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/hv60578286.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"REVIEWED","tsunami":null,"sig":96,"net":"hv","code":"60578286","ids":",hv60578286,","sources":",hv,","types":",cap,general-link,geoserve,nearby-cities,origin,","nst":null,"dmin":0.00898315,"rms":0.1,"gap":54,"magType":"Ml","type":"earthquake","title":"M 2.5 - 8km SSW of Volcano, Hawaii"},"geometry":{"type":"Point","coordinates":[-155.2747,19.3675,31.6]},"id":"hv60578286"},
{"type":"Feature","properties":{"mag":3.1,"place":"19km W of West Bishop, California","time":1382017510600,"updated":1382072572313,"tz":-420,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/nc72089491","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72089491.geojson","felt":2,"cdi":2.7,"mmi":null,"alert":null,"status":"AUTOMATIC","tsunami":null,"sig":148,"net":"nc","code":"72089491","ids":",nc72089491,","sources":",nc,","types":",dyfi,focal-mechanism,general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,","nst":null,"dmin":0.06288207,"rms":0.05,"gap":108,"magType":"Md","type":"earthquake","title":"M 3.1 - 19km W of West Bishop, California"},"geometry":{"type":"Point","coordinates":[-118.6773,37.3892,13.2]},"id":"nc72089491"},
{"type":"Feature","properties":{"mag":5.4,"place":"22km SSE of Lata, Solomon Islands","time":1382008392050,"updated":1382037346800,"tz":660,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kfhi","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kfhi.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":449,"net":"us","code":"b000kfhi","ids":",usb000kfhi,","sources":",us,","types":",cap,dyfi,geoserve,nearby-cities,origin,phase-data,tectonic-summary,","nst":null,"dmin":6.06,"rms":0.99,"gap":59,"magType":"mb","type":"earthquake","title":"M 5.4 - 22km SSE of Lata, Solomon Islands"},"geometry":{"type":"Point","coordinates":[165.9252,-10.8982,62.8]},"id":"usb000kfhi"},
{"type":"Feature","properties":{"mag":4.2,"place":"131km S of Puerto El Triunfo, El Salvador","time":1381997360900,"updated":1382026310261,"tz":-360,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kfgf","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kfgf.geojson","felt":null,"cdi":null,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":271,"net":"us","code":"b000kfgf","ids":",usb000kfgf,","sources":",us,","types":",cap,dyfi,general-link,geoserve,nearby-cities,origin,phase-data,tectonic-summary,","nst":null,"dmin":1.708,"rms":1.35,"gap":184,"magType":"mb","type":"earthquake","title":"M 4.2 - 131km S of Puerto El Triunfo, El Salvador"},"geometry":{"type":"Point","coordinates":[-88.5719,12.0947,40.04]},"id":"usb000kfgf"}],"bbox":[-177.3712,-28.9952,1.8,165.9252,60.258,215.63]}
6

You are getting this issue, because your GeoJSON data has Z coordinates.

By Default, OpenLayer's GeoJSON parser fails when it finds more than two coordinates (i.e X & Y).

To solve this issue, you must set the GeoJSON.ignoreExtraDims parameter to true.

Here is a sample JSFiddle which shows the code in actions.

  • That did it. Wish I had asked three days ago – Mark Cupitt Oct 18 '13 at 7:47
  • 2
    It's a stupid default, and isn't mentioned anywhere. I too had to spend a fair bit of time when I had faced this problem. – Devdatta Tengshe Oct 18 '13 at 7:53
  • It looks like the extra dim is the depth. Have you figured out a way to get that piece of info by any chance? – Mark Cupitt Oct 19 '13 at 2:08
  • I haven't been able to get that value. I feel that it would make an excellent question. Please post it as a new question. – Devdatta Tengshe Oct 19 '13 at 6:47

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.