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

Xastir improperly renders multi-part shapefile polylines as a single polyline #154

Open
tvrusso opened this issue Aug 2, 2019 · 4 comments

Comments

@tvrusso
Copy link
Member

tvrusso commented Aug 2, 2019

During investigation of some interesting shapefiles for bug #152, we discovered that Xastir is rendering certain shapes in a shapefile improperly.

These shapes are of polyline (SHPT_ARC or SHPT_ARCZ) with more than one "part". According to the shapelib API at http://shapelib.maptools.org/shp_api.html, a shape of ARC, POLYGON, or MULTIPOINT type may have parts. Xastir does not support MULTIPOINT, but we do support the other two. Multiple parts in a shape is indicated by a non-zero value of nParts in the SHPObject data structure returned by SHPReadObject function.

The code in map_shp.c for rendering SHPT_POLYGON polygons is in fact already careful to handle the case when nParts is nonzero, but the SHPT_ARC section of the code blindly constructs a single polyline out of the nVertices points it has in the shape, with no regard to the parts.

This code should be restructured so it looks at nParts, and properly loops over the parts constructing separate, unconnected polylines from them rather than treating the entire list of vertices as a single part.

Work on this would be much easier if issue #128 were closed first, because that would greatly simplify the map_shp.c file, making it much easier to read and modify.

@halmueller
Copy link
Contributor

As a workaround, in case you have multipart Shapefiles that you need to use now:
ogr2ogr -f "ESRI Shapefile" -nlt LINESTRING -explodecollections -lco ENCODING=UTF-8 output.shp input.shp
(from https://gis.stackexchange.com/a/226616/16406)

@tvrusso
Copy link
Member Author

tvrusso commented Aug 2, 2019

I should point out that the workaround suggested by @halmueller is probably a desirable thing to do even after this issue is corrected, because Xastir's shapefile renderer also tries to build an rtree spatial index out of shapes, and it is doing so based on the bounding box returned in the min/max coordinates of the object returned by SHPReadObject --- which doesn't tell anything about the multiple parts. It then uses that rtree to determine which shapes to read from the shape file based on whether the bounding box of the shape intersects the screen.

this means a truly enormous shape (such as one that has one part in one continent, another part half-way across the world) will never really be pruned from consideration.

The breaking up of the multipart shapes using ogr2ogr will work around THAT problem, too.

@tvrusso tvrusso added this to To do in Release 2.2.0 Aug 6, 2019
@godfreja
Copy link
Contributor

I think I will take a look at this one. Not an area of the code I am familiar with, but I believe I have an idea on what needs to be done.

@godfreja godfreja self-assigned this Feb 28, 2020
@godfreja godfreja moved this from To do to In progress in Release 2.2.0 Feb 28, 2020
@godfreja godfreja removed their assignment Mar 23, 2020
@godfreja
Copy link
Contributor

Not sure when I will get to this so un-assigning from myself for now.

@tvrusso tvrusso moved this from In progress to To do in Release 2.2.0 Jul 7, 2020
@tvrusso tvrusso removed this from To do in Release 2.2.0 Jul 27, 2023
tvrusso added a commit that referenced this issue Aug 6, 2023
map_shp.c (which I'm currently studying with an eye to tidying it up
and fixing issue #154), had a comment inserted during the original
creation of DBFAWK in 2003 (commit 62a8be7).  This comment referred to
"all this WX junk following" that was intended to discuss how DBFAWK
differed from the non-dbfawk code that was still there and enabled or
disabled by ifdef.

That code was deleted a long time ago in commit 3a9b6e1, but the
comment remained.

Now, instead of referring to code that no longer exists, it describes
what the code that still exists does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants