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

Results not as expected #13

Closed
feihugis opened this issue Jan 10, 2018 · 7 comments
Closed

Results not as expected #13

feihugis opened this issue Jan 10, 2018 · 7 comments

Comments

@feihugis
Copy link

Thanks for your library!

I'm trying to use this library to get the centerline of the roads (polygon). However, as the following figure show, besides the centerline, there are many short lines along the centerline. Is there any way to remove these short lines?

screen shot 2018-01-09 at 11 55 24 pm

@fitodic
Copy link
Owner

fitodic commented Jan 10, 2018

From what I can see, this polygon data set is very detailed. Nevertheless, there are several options you can look into:

  1. Modify the border density parameter (by default it is set to 0.5 meters)
  2. Simplify the polygon data set (e.g. QGIS)
  3. Simplify the centerline data set (e.g. QGIS)

@feihugis
Copy link
Author

@fitodic Thanks for your suggestion! The results got much better by simplifying the polygon data using Shapely simplify function.

@fitodic
Copy link
Owner

fitodic commented Jan 12, 2018

Glad I could help 🙂

@fitodic fitodic closed this as completed Jan 12, 2018
@ahomoudi
Copy link

ahomoudi commented Aug 22, 2020

I'm facing the same issue plus am quite new to Python thus I'm using the function of Centerline inside R. I have tried Shapely simplify function but still have extra lines at the end as shown in the figure. Any ideas for more improvement? Or how to apply the 1 & 3 option?

image

EDIT: simplifying centerline data set does not remove extra lines at the ends.

@fitodic
Copy link
Owner

fitodic commented Aug 25, 2020

@ahmathlete Hi :)
As to option 1, there is a parameter that increases or decreases the density of the input geometry:

>>> from shapely.geometry import Polygon
>>> from centerline.geometry import Centerline

>>> polygon = Polygon([[0, 0], [0, 4], [4, 4], [4, 0]])
>>> attributes = {"id": 1, "name": "polygon", "valid": True}

>>> centerline = Centerline(polygon, interpolation_distance=1.5, **attributes)

You can also pass the same value to the command line script.

As to option 3, you create the centerline dataset (e.g. using the create_centerline CLI command), open the centerline dataset in QGIS and manually delete the nodes that stick out.

@ahomoudi
Copy link

@fitodic Hello:)

Thanks for the helpful tips. Since am doing programmatically for large set of data, I will leave these steps in case someone will need it :

  1. Chaikin's corner-cutting algorithm with refinements degree of X0
  2. Shapely simplify function with a tolerance of X1
  3. Centerline function with interpolation distance X2

X0, X1, X2 values depend mainly on details of the work and desired results.

@fitodic
Copy link
Owner

fitodic commented Aug 26, 2020

@ahmathlete Thanks for clarifying 🙂
If you're willing, you can always update the documentation with this info. I know it depends on the dataset, but it never hurts to supply an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants