Giter Club home page Giter Club logo

Comments (6)

Robinlovelace avatar Robinlovelace commented on May 25, 2024

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

plot of chunk unnamed-chunk-1

# 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

unnamed-chunk-1-3

# test 2
n = 3
plot(l_new[n,]); plot(rf_new[n,], add = T) # succeed

from stplanr.

Robinlovelace avatar Robinlovelace commented on May 25, 2024

Also thinking it should be called line_match now as it's matching not merging.

from stplanr.

Robinlovelace avatar Robinlovelace commented on May 25, 2024

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.

richardellison avatar richardellison commented on May 25, 2024

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.

Robinlovelace avatar Robinlovelace commented on May 25, 2024

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?

unnamed-chunk-1-1

from stplanr.

edzer avatar edzer commented on May 25, 2024

Looks pretty trivial to add to CPL_geos_binop

from stplanr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.