Comments (6)
Update: the following code is moving towards a solution:
# Aim: prototype geographical joining function
library(stplanr)
# Create data in projected CRS with units of m
rf = routes_fast[5:1,] # wrong order
l = flowlines[1:5,]
proj4string(rf) = CRS("+init=epsg:4326")
rf = spTransform(rf, CRS("+init=epsg:27700"))
l = spTransform(l, CRS("+init=epsg:27700"))
# Test mismatch
plot(l); plot(l[2,], lwd = 5, add = T)
plot(rf[2,], add = T) # does not match
# Merge based on ods
l_od_coords = line2df(l)
rf_od_coords = line2df(rf)
sid1 = as.matrix(l_od_coords[-1])
sid2 = as.matrix(rf_od_coords[-1])
# install.packages("Hmisc")
m = Hmisc::find.matches(sid1, sid2, maxmatch = nrow(sid1),
tol = c(200, 200, 200, 200))
rf_new = rf[m$matches,]
l_new = l[1:length(l) %in% m$matches,]
# test 1
n = 1
plot(l[n,]); plot(rf[n,], add = T) # fail
```r
plot(l_new[n,]); plot(rf_new[n,], add = T) # works
# test 2
n = 3
plot(l_new[n,]); plot(rf_new[n,], add = T) # succeed
from stplanr.
Also thinking it should be called line_match
now as it's matching not merging.
from stplanr.
Problem: what do you do about lines like l[1,]
that have no match?
Suggestion: Print the line numbers in l1
with no match in l2
.
from stplanr.
Do you just want to use origin and destination coordinates to match lines?
Normally when I'm matching lines I typically use Hausdorff Distance in PostGIS or the gDistance function in rgeos because it accounts for differences in the paths of the lines (rather than just origin-destination).
from stplanr.
Aha that sounds good, although in our dataset it is the orgin and destination specifically that we're matching to. Interesting that there doesn't seem to be an implementation for sp objects in R, based on a rudimentary web search yet there is clearly a GEOS algorithm for this. Any plans for this related to sf/rgeos that you know of @edzer? Wondering where the best place for an R implementation to live would be and guessing rgeos.
Ah OK looking at the docs it seems hausdorff=TRUE
in gDistance()
would do the trick, e.g.
library(stplanr)
## Loading required package: sp
r = routes_fast[1:3,]
plot(r,
col = c("red", "yellow", "green"),
lwd = 3:1)
rgeos::gDistance(r, r, byid = T, hausdorff = T)
## 1 2 3
## 1 0.00000000 0.01569878 0.01209752
## 2 0.01569878 0.00000000 0.02130649
## 3 0.01209752 0.02130649 0.00000000
But why is the difference between 1 and 2, which seem very similar, 0.016 whereas 1 and 3, which seem very different, is only 0.012?
from stplanr.
Looks pretty trivial to add to CPL_geos_binop
from stplanr.
Related Issues (20)
- bug in the rnet_merge function when defining the funs HOT 3
- Use different buffer options in `rnet_merge()`
- Convert large GeoJSON file to PMTiles HOT 1
- bug in geo_buffer HOT 7
- Possible speed enhancement to `mats2line()` HOT 3
- Invalid LineStrings in routes_fast_sf HOT 1
- Use `od::odc_to_sfc()` do the legwork in `mats2line()` HOT 3
- Bug in `line_segment()` when using certain values on projected data with `rsgeo` implementation HOT 8
- `rnet_merge()` fails when inputs are projected HOT 4
- `line_bearing()` is slow HOT 3
- Argument of segment_length in line_segment fun causes issue HOT 14
- Tried creating a route from desirelines using osrm function HOT 9
- rnet merge function can't not handle attributes containing strings HOT 1
- Add links to more papers in DESCRIPTION
- Re-add n_segments argument to line_segment() HOT 1
- `line_segment()` fails when n_segments has multiple values HOT 1
- od2line() throws an error if only one origin-destination relation is selected HOT 5
- Tests fail if {rsgeo} is not installed
- Work-around rsgeo not on cran
- Checks when Suggests are unavailable HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stplanr.