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

Bpoly feature #69

Merged
merged 12 commits into from
Jul 6, 2021
Merged

Bpoly feature #69

merged 12 commits into from
Jul 6, 2021

Conversation

matthiasschaub
Copy link
Collaborator

@matthiasschaub matthiasschaub commented Jun 28, 2021

Description

  • Change type of attribute bpolys to be GeoJSON.Feature.
  • Input bpolys to API can be of type GeoJSON.Feature with the geometry type Polygon or MultiPolygon. Input can also only contain the geometry.
  • Input file to API can be any valid GeoJSON. Geometry type has to be Polygon or MultiPolygon
  • Improve type hints.

Corresponding issue

Closes #9

Checklist

  • support FeatureCollection with only one Feature (again)
  • I have updated my branch to main (e.g. through git rebase main)
  • My code follows the style guide and was checked with pre-commit before committing
  • I have commented my code
  • I have added sufficient unit and integration tests
  • I have updated the CHANGELOG.md

CHANGELOG.md Outdated Show resolved Hide resolved
workers/ohsome_quality_analyst/api.py Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Comment on lines 55 to 63
def int_or_str_param_type(value: str) -> Union[int, str]:
"""Parse parameter as Interger otherwise parse as String"""
try:
return int(value)
except (ValueError, TypeError):
if isinstance(value, str):
return value
else:
raise ValueError("Given parameter is not a valid integer or string")
Copy link
Member

Choose a reason for hiding this comment

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

Do you have an example where this could be required? As far as I see, this is only used for the feature_id. The feature id given by a GET/POST request should always be given as a string, afaik. If you want to prevent the parameter from being optional, I would check/set this with fastAPI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes you are right. The else statement is never reached. Except maybe when None is passed as argument. But before calling this function it is checked whether feature id is none or not.

Copy link
Member

Choose a reason for hiding this comment

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

I meant in general, why do you want a variable which is either int or str? In the database you can only handle one of them, right? So you can handle all identifier in OQT as string, or did I miss a problem with that? I think it would be much easier to focus on one type for identifier 😉

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, now I see what you mean.
Since #37 feature_id can be str or int depending on what feature_id_field is.

E.g.

# int in the database
oqt create-indicator --fid-field ogc_fid --feature-id 1
# str in the database
oqt create-indicator --fid-field name --feature-id heidelberg

What do you think about this behavior?

workers/ohsome_quality_analyst/api.py Outdated Show resolved Hide resolved
workers/ohsome_quality_analyst/api.py Outdated Show resolved Hide resolved
workers/ohsome_quality_analyst/api.py Outdated Show resolved Hide resolved
Comment on lines 55 to 63
def int_or_str_param_type(value: str) -> Union[int, str]:
"""Parse parameter as Interger otherwise parse as String"""
try:
return int(value)
except (ValueError, TypeError):
if isinstance(value, str):
return value
else:
raise ValueError("Given parameter is not a valid integer or string")
Copy link
Member

Choose a reason for hiding this comment

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

I meant in general, why do you want a variable which is either int or str? In the database you can only handle one of them, right? So you can handle all identifier in OQT as string, or did I miss a problem with that? I think it would be much easier to focus on one type for identifier 😉

Copy link
Member

@joker234 joker234 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR and the additional tests 👍 I made some additional comments, but in general, the PR looks good.

@joker234 joker234 removed the waiting for review This pull request urgently needs a code review label Jul 6, 2021
@matthiasschaub
Copy link
Collaborator Author

@joker234 Thanks for your attentive feedback! I addressed most of your feedback directly in the code. Some discussions are still open.

Parse and extract Geometry from input GeoJSON

Input to the API is a valid GeoJSON. The function load_bpolys() will extract the geometry of this
GeoJSON and validate it.

Rename fixture file

Add missing type hint

Make bpolys attribute madatory for indicator class

Add changes to CHANGELOG

Update fixtures
after load_bpolys() has been called.
joker234
joker234 previously approved these changes Jul 6, 2021
@matthiasschaub matthiasschaub merged commit 06b00ab into main Jul 6, 2021
@matthiasschaub matthiasschaub deleted the bpoly-feature branch July 6, 2021 14:18
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

Successfully merging this pull request may close these issues.

The attribute bpolys of indicators should be of type Feature or MultiPolygon not FeatureCollection
2 participants