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

Need to dynamically read optional fields? #25

Closed
cchderrick opened this issue Nov 1, 2018 · 5 comments
Closed

Need to dynamically read optional fields? #25

cchderrick opened this issue Nov 1, 2018 · 5 comments

Comments

@cchderrick
Copy link
Contributor

As it seems from shapelib implementation, the reader will need to check if the number of Content Length (in bytes) matches Number of points for these record types:
MultiPointM
PolyLineM
PolygonM
MultiPointZ
PolyLineZ
PolygonZ
MultiPatch

For example:
PolyLineM record with 1 part and 10 points, without M, the content length would be 44 + (4 * 1) + (16 * 10), with M, the content length becomes 44 + (4 * 1) + (16 * 10) + the optional 8 + 8 + (8 * 10)

@visr
Copy link
Member

visr commented Nov 17, 2018

I don't think I fully understand. A PolyLineM always has an M coordinate right? If it doesn't it is a PolyLine.

We can of course add a check on the content length, but isn't how much we read currently already decided by numparts, numpoints, etc?

@cchderrick
Copy link
Contributor Author

The ESRI Shapefile spec allows Z or M parts to be optional for some of the type.

And looking at the shapelib C implementation in GDAL, it seems like it also do some sort of size check to determine if the optional fields are presented.

Ref:
https://github.com/OSGeo/gdal/blob/master/gdal/ogr/ogrsf_frmts/shape/shpopen.c#L2523-L2529

@visr
Copy link
Member

visr commented Dec 12, 2018

For me it's much easier to read the technical description: https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf

There it says that for measures only, floats smaller than -1e38 are considered "no data".

@cchderrick
Copy link
Contributor Author

Okay, I think I have misunderstood the word "Optional" in the spec. What I thought it meant the data array could be omitted from the file. Upon some more research, what the spec really meant for "Optional" is the M array can all be filled with no-data values.

@visr
Copy link
Member

visr commented Dec 13, 2018

Ah yeah I see, it is quite confusing. Since there is still a possible improvement for explicitly handling missing measures, I opened up #28. Thanks!

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

2 participants