Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find nearest lines, edges, and nodes #209

Merged
merged 30 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a82e8cc
utility to find nearest edges and nodes for a given node
geohacker Apr 21, 2020
6bdf5ad
fix the distance to 20m. test for an edge of a way
geohacker Apr 23, 2020
96cf8a9
find nearest nodes on the edges
geohacker Apr 27, 2020
38a0163
new fixtures
geohacker Apr 27, 2020
8961986
find a point to snap to on an edge
geohacker Apr 27, 2020
21f17e3
missing package
geohacker Apr 27, 2020
4ea2ab5
lint
geohacker Apr 27, 2020
6f09658
🤦‍♀️ fix incorrect import
geohacker Apr 27, 2020
0f29cb2
wire up nearest in edit way mode. find the ids of the members
geohacker Apr 28, 2020
9ca28e3
hide the nodes when a feature is deselected
geohacker Apr 29, 2020
0ee670c
renove duplicate nodes. add nodes and edges to the map
geohacker Apr 30, 2020
425e396
always return one node that's closest. either a member node or a poin…
geohacker May 4, 2020
6b41fc0
adjustments to make the edge and the node visible
geohacker May 4, 2020
b8c3158
snap/use the node that's nearest when available
geohacker May 4, 2020
ca7fc66
include nodes from the current way also as part of nearest calculation
geohacker May 4, 2020
e189bcc
use osmtogeojson with node reverse references. update nodecache servi…
geohacker May 5, 2020
3149269
update test snapshot
geohacker May 5, 2020
e299c6a
yarn.lock
geohacker May 5, 2020
0cac815
When no feature is available, set empty object
vgeorge May 5, 2020
f59faa2
Keep nodes from selected feature in redux state
vgeorge May 5, 2020
ae2956e
Do not update state.map.nodes with action SET_SELECTED_WAY
vgeorge May 6, 2020
cb797ee
logic for modifying ways with shared nodes, moving nodes renders inte…
geohacker May 6, 2020
8c5530c
Merge branch 'nearest' of github.com:developmentseed/observe into nea…
geohacker May 6, 2020
d946c19
Add a separate source for the editing way member nodes
vgeorge May 6, 2020
5245f22
remove unwanted filter on member node layer. member nodes need to be …
geohacker May 7, 2020
d5bce21
Merge pull request #213 from developmentseed/fix/selected-member-node…
vgeorge May 7, 2020
18ac62c
modify ways when shared node is deleted. move modify logic to a util
geohacker May 7, 2020
39ca523
Merge branch 'nearest' of github.com:developmentseed/observe into nea…
geohacker May 7, 2020
4aa4969
get nearest edge and node to show up on android
geohacker May 7, 2020
27e7f2f
make sure move and delete uses properties and do a deep clone. weirdl…
geohacker May 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,065 changes: 5,065 additions & 0 deletions __tests__/fixtures/dc-nodes.json

Large diffs are not rendered by default.

3,338 changes: 3,338 additions & 0 deletions __tests__/fixtures/osm-geojson-dc.geojson

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions __tests__/services/__snapshots__/nodecache.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,37 @@ Object {
"node/8548730": Object {
"lat": "38.9005771",
"lon": "-77.0224428",
"ways": null,
},
"node/8548853": Object {
"lat": "38.8998216",
"lon": "-77.0219243",
"ways": null,
},
"node/8548854": Object {
"lat": "38.8998216",
"lon": "-77.0219243",
"ways": null,
},
"node/8548856": Object {
"lat": "38.9008903",
"lon": "-77.0219297",
"ways": null,
},
"node/8548857": Object {
"lat": "38.9021135",
"lon": "-77.0219297",
"ways": null,
},
"node/8548858": Object {
"lat": "38.9021135",
"lon": "-77.0219297",
"ways": null,
},
"node/8548859": Object {
"lat": "38.9028942",
"lon": "-77.0218653",
"ways": null,
},
}
`;
Expand All @@ -51,60 +58,74 @@ Object {
"node/8548730": Object {
"lat": "38.9005771",
"lon": "-77.0224428",
"ways": null,
},
"node/8548853": Object {
"lat": "38.8998216",
"lon": "-77.0219243",
"ways": null,
},
"node/8548854": Object {
"lat": "38.8998216",
"lon": "-77.0219243",
"ways": null,
},
"node/8548856": Object {
"lat": "38.9008903",
"lon": "-77.0219297",
"ways": null,
},
"node/8548857": Object {
"lat": "38.9021135",
"lon": "-77.0219297",
"ways": null,
},
"node/8548858": Object {
"lat": "38.9021135",
"lon": "-77.0219297",
"ways": null,
},
"node/8548859": Object {
"lat": "38.9028942",
"lon": "-77.0218653",
"ways": null,
},
},
"0320100322313213": Object {
"node/8548730": Object {
"lat": "38.9005771",
"lon": "-77.0224428",
"ways": null,
},
"node/8548853": Object {
"lat": "38.8998216",
"lon": "-77.0219243",
"ways": null,
},
"node/8548854": Object {
"lat": "38.8998216",
"lon": "-77.0219243",
"ways": null,
},
"node/8548856": Object {
"lat": "38.9008903",
"lon": "-77.0219297",
"ways": null,
},
"node/8548857": Object {
"lat": "38.9021135",
"lon": "-77.0219297",
"ways": null,
},
"node/8548858": Object {
"lat": "38.9021135",
"lon": "-77.0219297",
"ways": null,
},
"node/8548859": Object {
"lat": "38.9028942",
"lon": "-77.0218653",
"ways": null,
},
},
}
Expand Down
181 changes: 181 additions & 0 deletions __tests__/utils/__snapshots__/nearest.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`find nearest features for a node 1`] = `
Object {
"nearestEdge": Object {
"geometry": Object {
"coordinates": Array [
Array [
-77.0243788,
38.902298,
],
Array [
-77.025819,
38.9022963,
],
],
"type": "LineString",
},
"properties": Object {
"distance": 0.000225172520188007,
"parent_feature": Object {
"geometry": Object {
"coordinates": Array [
Array [
Array [
-77.025819,
38.9022963,
],
Array [
-77.0258367,
38.901784,
],
Array [
-77.0257263,
38.9017169,
],
Array [
-77.0243478,
38.902212,
],
Array [
-77.0243788,
38.902298,
],
Array [
-77.025819,
38.9022963,
],
],
],
"type": "Polygon",
},
"id": "way/4294967474",
"properties": Object {
"building": "yes",
"changeset": "17237",
"id": "way/4294967474",
"ndrefs": Array [
"4294969101",
"4294969102",
"4294969103",
"4294969104",
"4294969105",
"4294969101",
],
"timestamp": "2013-01-16T15:30:19Z",
"uid": "181",
"user": "samlarsen1",
"version": "1",
},
"type": "Feature",
},
},
"type": "Feature",
},
"nearestNode": Object {
"geometry": Object {
"coordinates": Array [
-77.02439999610696,
38.90229797498029,
],
"type": "Point",
},
"properties": Object {
"dist": 0.00022517248045479096,
"id": "observe-hauptbanhof",
"index": 0,
"location": 0.0018341862152104543,
},
"type": "Feature",
},
}
`;

exports[`find nearest features for a node 2`] = `
Object {
"nearestEdge": Object {
"geometry": Object {
"coordinates": Array [
Array [
-77.028073,
38.9025312,
],
Array [
-77.0270204,
38.9025427,
],
Array [
-77.026122,
38.9025391,
],
Array [
-77.0239954,
38.9025095,
],
],
"type": "LineString",
},
"id": "way/4294967325",
"properties": Object {
"changeset": "17292",
"distance": 0.0018370829928528922,
"highway": "residential",
"id": "way/4294967325",
"ndrefs": Array [
"4294967647",
"4294969574",
"4294967648",
"4294967649",
],
"timestamp": "2013-01-18T14:28:15Z",
"uid": "15",
"user": "TomH",
"version": "2",
},
"type": "Feature",
},
"nearestNode": Object {
"geometry": Object {
"coordinates": Array [
-77.02449962009433,
38.90251651820502,
],
"type": "Point",
},
"properties": Object {
"dist": 0.0018370373094811034,
"id": "observe-hauptbanhof",
"index": 2,
"location": 0.3092503207620726,
},
"type": "Feature",
},
}
`;

exports[`find nearest features for a node 3`] = `
Object {
"nearestEdge": null,
"nearestNode": null,
}
`;

exports[`find nearest features for a node 4`] = `
Object {
"geometry": Object {
"coordinates": Array [
-77.02449962009433,
38.90251651820502,
],
"type": "Point",
},
"properties": Object {
"dist": 0.0018370373094811034,
"id": "observe-hauptbanhof",
"index": 2,
"location": 0.3092503207620726,
},
"type": "Feature",
}
`;
57 changes: 57 additions & 0 deletions __tests__/utils/nearest.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* global test */
/* global expect */
/* global __dirname */

import fs from 'fs'
import path from 'path'
import { findNearestPoint, findNearest } from '../../app/utils/nearest'
import { addNodes } from '../../app/services/nodecache'

test('find nearest features for a node', async () => {
const features = JSON.parse(fs.readFileSync(path.join(__dirname, '../fixtures/osm-geojson-dc.geojson'), { 'encoding': 'utf-8' }))

const nodes = JSON.parse(fs.readFileSync(path.join(__dirname, '../fixtures/dc-nodes.json'), { 'encoding': 'utf-8' }))
const tile = '0320100322313212'
await addNodes(tile, nodes)

// node close to a polygon
const node1 = {
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [-77.0244, 38.9023]
},
'properties': {}
}

// node close to a linestring
const node2 = {
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [-77.0245, 38.9025]
},
'properties': {}
}

const node3 = {
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [-77.0246, 38.9024]
},
'properties': {}
}

const nearest1 = await findNearest(node1, features)
const nearest2 = await findNearest(node2, features)
const nearest3 = await findNearest(node3, features)

expect(nearest1).toMatchSnapshot()
expect(nearest2).toMatchSnapshot()
expect(nearest3).toMatchSnapshot()

const edge = nearest2.nearestEdge
const snappedPoint = findNearestPoint(node2, edge)
expect(snappedPoint).toMatchSnapshot()
})
1 change: 1 addition & 0 deletions app/actions/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const WAY_SET_SELECTED_NODE = 'WAY_SET_SELECTED_NODE'
export const WAY_EDIT_MOVE_NODE = 'WAY_EDIT_MOVE_NODE'
export const WAY_EDIT_DELETE_NODE = 'WAY_EDIT_DELETE_NODE'
export const WAY_EDIT_MODE_ADD = 'WAY_EDIT_MODE_ADD'
export const FIND_NEAREST_FEATURES = 'FIND_NEAREST_FEATURES'

// Undo/Redo functionality
export const UNDOABLE_UNDO = 'UNDOABLE_UNDO'
Expand Down
Loading