-
Notifications
You must be signed in to change notification settings - Fork 372
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
Support id for GeoJSONFeature #994
Conversation
kunlinyu
commented
Nov 15, 2023
- Add id and getter for GeoJSONFeature
- Modify the copy constructor of GeoJSONFeature
- Check "id" in GeoJSONReader
- Check "id" in GeoJSONWriter
- Modify unit test for id
1. Add id and getter for GeoJSONFeature 2. Modify the copy constructor of GeoJSONFeature 3. Check "id" in GeoJSONReader 4. Check "id" in GeoJSONWriter 5. Modify unit test for id Signed-off-by: Kunlin Yu <[email protected]>
src/io/GeoJSONReader.cpp
Outdated
return GeoJSONFeature{readGeometry(geometryJson), readProperties(properties)}; | ||
|
||
std::string id = ""; | ||
if (j.contains("id")) id = j.at("id").get<std::string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will that work if "id" is null, or some non-string type ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, seems worrisome :)
Signed-off-by: Kunlin Yu <[email protected]>
src/io/GeoJSONReader.cpp
Outdated
std::string id = ""; | ||
if (j.contains("id") && !j.at("id").is_null()) { | ||
if (j.at("id").is_string()) id = j.at("id").get<std::string>(); | ||
if (j.at("id").is_number()) id = std::to_string(j.at("id").get<int>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does get() works fine on floating-point numbers ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works fine but I think it is not correct. According to the geojson standard, all number is valid. So we have to support float point. I will upload a patch soon.
Use "dump()" instead of get<int>() or get<float>() to make code clear. And notice that both 123.0 and 123.000 will be parsed as "123.0" because nlohmann/json will cut the suffix 0 by default. It is hard to support float well. But I think use floating-point as id is not a good practice. So I think then current implementation is acceptable. Signed-off-by: Kunlin Yu <[email protected]>