I do miss Pokemon. ANYWAYS, onto the meat of the post. Last time, I spoke about organising data into JSON objects that I could work with. I also told you I was only doing that so I could understand JSON before moving onto GeoJSON. Well. Guess what. GeoJSON IS JUST A JSON OBJECT WITH A PARTICULAR STRUCTURE. Talk about an anticlimax.
HERE is the final code for scraping HTML and storing it as JSON objects. And HERE is the new code for doing the same thing but storing it as a GeoJSON object. For a detailed breakdown of what a GeoJSON object looks like, go HERE. If you can’t be bothered to read through it and figure it out, usually I would tell you to leave me alone. But I’m in a giving mood so I’m gonna explain it.
- A GeoJSON object is ONE JSON object.
- It is made up of TWO properties:
- A “features” property
- A “type” property
- The “type” property is always set to “FeatureCollection” (side not: I’m not sure how important capitalisation is in JSON, but err on the side of caution until you find out)
- The “features” property is always an array containing objects that represent your geographical data
- Each object representing your geographical data contains three properties:
- A “type” property
- A “geometry” property
- A “properties” property
- The “type” property is always set to “Feature” as that is what each geographical object is called
- The “geometry” property always contains an object that represents your exact geographical data and has two properties:
- A “type” property that defines the type of data (point, multipoint, coordinates, etc.)
- A “coordinates” property that contains the numbers representing your geographical data. It is either an array of numbers or an array of arrays of numbers. Easy on the brain and tongue, right?
- The “properties” property represents an object that contains any properties you want this specific feature to have a la typical JSON fashion
DAS IT. Again, look at the spec page I linked to for more detailed information. If you look at my code, all I’m doing is translating the above into computer speak. It feels awkward at first because you’re creating an object that represents a property and an array, and the array represents objects that represent a property, an object that represents more properties and arrays, and an object that represents even more properties.
Please go away.