fitodic / centerline

Calculate the polygon's centerline
https://centerline.readthedocs.io
MIT License
266 stars 55 forks source link

Can not install version 1.0 #37

Closed phamkhactu closed 1 year ago

phamkhactu commented 1 year ago

Hi @fitodic I think maybe version haven't updated because something wrong

ERROR: Could not find a version that satisfies the requirement centerline==1.0.0 (from versions: 0.1, 0.2, 0.2.1, 0.3, 0.4, 0.4.1, 0.4.2, 0.5, 0.5.2, 0.6.0, 0.6.3, 0.6.4)
ERROR: No matching distribution found for centerline==1.0.0

Can you review it. Thank you.

fitodic commented 1 year ago

What Python version are you using? It works on 3.11.1, and the minimum supported version is 3.8

phamkhactu commented 1 year ago

What Python version are you using? It works on 3.11.1, and the minimum supported version is 3.8

Thank you @fitodic . I have installed sucessfully, but I get error, I think that maybe it comes from data is lat long. I'm very happy if you can give me example to face with lat long:

    centerline = Centerline(polygon,  **attributes)
  File "/home/tupk/anaconda3/envs/dl/lib/python3.8/site-packages/centerline/geometry.py", line 43, in __init__
    self.geometry = MultiLineString(lines=self._construct_centerline())
  File "/home/tupk/anaconda3/envs/dl/lib/python3.8/site-packages/centerline/geometry.py", line 74, in _construct_centerline
    vertices, ridges = self._get_voronoi_vertices_and_ridges()
  File "/home/tupk/anaconda3/envs/dl/lib/python3.8/site-packages/centerline/geometry.py", line 97, in _get_voronoi_vertices_and_ridges
    voronoi_diagram = Voronoi(borders)
  File "qhull.pyx", line 2615, in scipy.spatial.qhull.Voronoi.__init__
  File "qhull.pyx", line 357, in scipy.spatial.qhull._Qhull.__init__
scipy.spatial.qhull.QhullError: QH6214 qhull input error: not enough points(2) to construct initial simplex (need 4)

While executing:  | qhull v Qbb Qc Qz
Options selected for Qhull 2019.1.r 2019/06/21:
  run-id 773912307  voronoi  Qbbound-last  Qcoplanar-keep  Qz-infinity-point
  _pre-merge  _zero-centrum  Qinterior-keep  _maxoutside  0

Here is my code:

import shapely
from shapely.ops import transform
# from shapely.plotting import plot_polygon
from shapely.geometry import shape
from centerline.geometry import Centerline
from shapely.geometry import Polygon, Point, LineString, MultiPoint
import numpy as np 
from shapely.plotting import plot_polygon

d = { "type": "Feature", "properties": { "OBJECTID": 6.0, "SHAPE_Leng": 0.0018435614763720001, "SHAPE_Area": 1.830693e-08, "name": None, "rongMax": None, "rongMin": None, "rongTB": None }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 105.814233473000058, 21.009605263000026 ], [ 105.814270254000064, 21.009557108000024 ], [ 105.814294123000082, 21.009508220000043 ], [ 105.814310222000074, 21.00947741400006 ], [ 105.814272326000037, 21.009456668000041 ], [ 105.814212241000064, 21.009415109000031 ], [ 105.81420315400004, 21.00940840100003 ], [ 105.81417328200007, 21.009386347000031 ], [ 105.814165209000066, 21.009398109000074 ], [ 105.814144615000032, 21.009394712000073 ], [ 105.814124802000038, 21.009382587000061 ], [ 105.814117689000057, 21.009392403000049 ], [ 105.814070315000038, 21.009362398000064 ], [ 105.814035767000064, 21.00933989300006 ], [ 105.81399544900006, 21.009314226000072 ], [ 105.813992317000043, 21.00931666200006 ], [ 105.813938111000084, 21.009278877000042 ], [ 105.813956262000033, 21.009253924000063 ], [ 105.813898282000082, 21.009273615000041 ], [ 105.813906806000034, 21.009281664000071 ], [ 105.813926242000036, 21.009296736000067 ], [ 105.813930008000057, 21.009292257000027 ], [ 105.814022481000052, 21.009355528000071 ], [ 105.814091046000044, 21.009398283000053 ], [ 105.814108600000054, 21.009407042000078 ], [ 105.814147095000067, 21.009413957000049 ], [ 105.814147350000042, 21.009413089000077 ], [ 105.814174914000034, 21.009421213000053 ], [ 105.814174412000057, 21.009422525000048 ], [ 105.814199988000041, 21.009438416000023 ], [ 105.814196086000038, 21.00944436900005 ], [ 105.81427995100006, 21.009495137000044 ], [ 105.81422490500006, 21.009573164000074 ], [ 105.814231047000078, 21.009576607000042 ], [ 105.814197398000033, 21.009632903000067 ], [ 105.814200504000041, 21.009634568000024 ], [ 105.814165204000062, 21.009698650000075 ], [ 105.814130529000067, 21.009681203000071 ], [ 105.814110726000081, 21.009670929000038 ], [ 105.814077452000049, 21.00965476600004 ], [ 105.814043983000033, 21.009639770000035 ], [ 105.814037492000068, 21.009636667000052 ], [ 105.814028830000041, 21.009653373000049 ], [ 105.814056730000061, 21.009666333000041 ], [ 105.814085146000082, 21.009679532000064 ], [ 105.814120301000059, 21.009698368000045 ], [ 105.814155253000081, 21.009715444000051 ], [ 105.81417351500005, 21.009716377000075 ], [ 105.814180653000051, 21.009702379000032 ], [ 105.814231116000087, 21.009606946000076 ], [ 105.814233473000058, 21.009605263000026 ] ] ] ] } }
geom = shape(d['geometry'])
coord_ori = d["geometry"]['coordinates']
coord_ori = np.array(coord_ori)
coord_ori = coord_ori.reshape((51,2))
# print(coord.shape)

length = coord_ori.shape[0]
coord = coord_ori[:length-1]

polygon = Polygon(coord)
attributes = {"id": 1, "name": "polygon", "valid": True}
centerline = Centerline(polygon,  **attributes)
print(centerline)
plot_polygon(geom)
plt.show()
fitodic commented 1 year ago

The coordinates are probably in degrees, so what I'd recommend is to adjust the interpolation_distance parameter to a lower level as specified in the docs. For example,

polygon = Polygon(coord)
attributes = {"id": 1, "name": "polygon", "valid": True}
centerline = Centerline(polygon, interpolation_distance=0.00001, **attributes)
...

Long-term, the library should return a custom error in that spot with a more meaningful message.

phamkhactu commented 1 year ago

The coordinates are probably in degrees, so what I'd recommend is to adjust the interpolation_distance parameter to a lower level as specified in the docs. For example,

polygon = Polygon(coord)
attributes = {"id": 1, "name": "polygon", "valid": True}
centerline = Centerline(polygon, interpolation_distance=0.00001, **attributes)
...

Long-term, the library should return a custom error in that spot with a more meaningful message.

@fitodic thank you. I have another question that: How to get the main skeleton ?? It means that: keep only smooth centerline and how to get value of firstpoint or firstline start and endline image From image, I want to remove some edge(linestring) I have highlight Many thanks

fitodic commented 1 year ago

Unfortunately, this is a side-effect of the algorithm. Depending on the input geometry's shape, the Voronoi diagram can produce these spruces which I usually remove manually using QGIS.

phamkhactu commented 1 year ago

@fitodic thank you, one more time, thank you very much