seattleio / seattle-boundaries-data

geojson for various boundaries in Seattle
45 stars 52 forks source link

Boundary check #18

Closed sethvincent closed 8 years ago

sethvincent commented 8 years ago

This turns the main javascript module in this repo into a function that takes long/lat point as input and checks which boundaries the point is inside.

First step toward creating a boundary api service!

It required cleaning a couple of datasets that were using the GeometryCollection geojson type, which isn't supported very well by turf, the tool I'm using to check if the point is inside a boundary.

Returns a FeatureCollection where all the features are a match for the point. The slug of the dataset that the feature is from is stored in the properties of the feature with the key dataset.

Calling the function looks like this:

var boundaries = require('seattle-boundaries')
boundaries(-122.345002, 47.667044)

Which returns something like this:

{ type: 'FeatureCollection',
  features: 
   [ { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', geometry: [Object], properties: [Object] },
     { type: 'Feature',
       id: 167,
       properties: [Object],
       geometry: [Object] },
     { type: 'Feature', geometry: [Object], properties: [Object] },
     { type: 'Feature',
       id: 1329,
       properties: [Object],
       geometry: [Object] },
     { type: 'Feature',
       id: 52,
       properties: [Object],
       geometry: [Object] },
     { type: 'Feature',
       id: 3,
       properties: [Object],
       geometry: [Object] },
     { type: 'Feature',
       id: 2,
       properties: [Object],
       geometry: [Object] },
     { type: 'Feature',
       id: 86,
       properties: [Object],
       geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] } ] }

In each feature there is a property with a key of dataset where the value is the slug of the dataset that the feature is from.

sethvincent commented 8 years ago

Oh wait, I just realized the function should probably return a FeatureCollection

Don't merge yet. I'm going to do that.

sethvincent commented 8 years ago

OK. The function now returns a FeatureCollection with the slug of the dataset that each feature is from stored as a property on the feature. This should work well, I think.