Skip to content

Bug in map2loop sampler after #57 #73

@lachlangrose

Description

@lachlangrose

@AngRodrigues I came across this bug when trying to run map2loop on a QLD dataset for Alex. The error occurs when map2loop is trying to calculate the basal contacts and seems to be an issue in shapely trying to create a shape, the error says there are not enough coordinates should there be a check before making the polygon to see that there are at least 4 points?

The line it fails for is:

LINESTRING (587704.9157154277 7778683.345154569, 587704.9162529807 7778684.38485311)

For reference the shapefile is geology.zip

`File ~/miniconda3/envs/loop/lib/python3.10/site-packages/map2loop/project.py:397, in Project.extract_geology_contacts(self)
395 # Use stratigraphic column to determine basal contacts
396 self.map_data.extract_basal_contacts(self.stratigraphic_column.column)
--> 397 self.map_data.sampled_contacts = self.samplers[Datatype.GEOLOGY].sample(
398 self.map_data.basal_contacts
399 )
400 self.map_data.get_value_from_raster_df(Datatype.DTM, self.map_data.sampled_contacts)

File <@beartype(map2loop.sampler.SamplerSpacing.sample) at 0x75933ceeed40>:56, in sample(__beartype_object_102539819504416, __beartype_get_violation, __beartype_conf, __beartype_object_129278881410176, __beartype_object_102539814178272, __beartype_func, *args, **kwargs)

File ~/miniconda3/envs/loop/lib/python3.10/site-packages/map2loop/sampler.py:157, in SamplerSpacing.sample(self, spatial_data, map_data)
153 if target_polygon.exterior.is_ccw: # if counterclockwise --> hole
154 for j, target2 in enumerate(
155 targets
156 ): # which poly is the hole in? assign featureId of the same poly
--> 157 t2_polygon = shapely.geometry.Polygon(target2)
158 if target.within(t2_polygon): #
159 df2['featureId'] = str(j)

File ~/miniconda3/envs/loop/lib/python3.10/site-packages/shapely/geometry/polygon.py:230, in Polygon.new(self, shell, holes)
228 return shell
229 else:
--> 230 shell = LinearRing(shell)
232 if holes is not None:
233 if len(holes) == 0:
234 # shapely constructor cannot handle holes=[]

File ~/miniconda3/envs/loop/lib/python3.10/site-packages/shapely/geometry/polygon.py:104, in LinearRing.new(self, coordinates)
99 if len(coordinates) == 0:
100 # empty geometry
101 # TODO better constructor + should shapely.linearrings handle this?
102 return shapely.from_wkt("LINEARRING EMPTY")
--> 104 geom = shapely.linearrings(coordinates)
105 if not isinstance(geom, LinearRing):
106 raise ValueError("Invalid values passed to LinearRing constructor")

File ~/miniconda3/envs/loop/lib/python3.10/site-packages/shapely/decorators.py:77, in multithreading_enabled..wrapped(*args, **kwargs)
75 for arr in array_args:
76 arr.flags.writeable = False
---> 77 return func(*args, **kwargs)
78 finally:
79 for arr, old_flag in zip(array_args, old_flags):

File ~/miniconda3/envs/loop/lib/python3.10/site-packages/shapely/creation.py:173, in linearrings(coords, y, z, indices, out, **kwargs)
171 coords = _xyz_to_coords(coords, y, z)
172 if indices is None:
--> 173 return lib.linearrings(coords, out=out, **kwargs)
174 else:
175 return simple_geometries_1d(coords, indices, GeometryType.LINEARRING, out=out)

ValueError: A linearring requires at least 4 coordinates.
`

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingongoingthis is being followed up by the team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions