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

Support id for GeoJSONFeature #994

Merged
merged 3 commits into from
Nov 22, 2023
Merged

Support id for GeoJSONFeature #994

merged 3 commits into from
Nov 22, 2023

Conversation

kunlinyu
Copy link
Contributor

  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

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]>
return GeoJSONFeature{readGeometry(geometryJson), readProperties(properties)};

std::string id = "";
if (j.contains("id")) id = j.at("id").get<std::string>();
Copy link
Contributor

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 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, seems worrisome :)

@dr-jts dr-jts added the Enhancement New feature or feature improvement. label Nov 20, 2023
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>());
Copy link
Contributor

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 ?

Copy link
Contributor Author

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]>
@kunlinyu kunlinyu requested a review from rouault November 22, 2023 11:44
@pramsey pramsey merged commit b3415ca into libgeos:main Nov 22, 2023
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or feature improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants