-
Notifications
You must be signed in to change notification settings - Fork 16
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
WIP: [8472] Migrate project point to GeoDjango and add a new serializer mixin to convert between gis and geojson #1765
base: main
Are you sure you want to change the base?
Conversation
8517541
to
3599699
Compare
points as GeoDjango to the database for better filtering capabilites and serializes them as geojson features. - add PointInPolygon validator which validates that a given point is in the provided polygon.
3599699
to
f89db5d
Compare
@goapunk what's your concern at this point? |
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.
Thank you for this surgical operation :)
It needs a good docs, with payload example and an explanation on why we keep both paradigms, and maybe in the future all map based modules should migrate to django gis
if "properties" in point: | ||
for property in properties: | ||
if property in point["properties"]: | ||
data[property] = point["properties"][property] |
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.
this if block (line 22 - 25) is hard to read, anyway to re-write it? or add some extra comments.
kwargs = super().get_form_kwargs() | ||
if "data" in kwargs: | ||
data = self.unpack_geojson(kwargs["data"]) | ||
kwargs["data"] = data |
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.
same here
self.polygon = polygon | ||
|
||
def __call__(self, value): | ||
"""""" |
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.
what are these quotes for?
name="point", | ||
), | ||
migrations.AddField( | ||
model_name="project", |
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.
I think once data has migrated wth migrate_project_point_field
and old point
filed is removed you can just rename the field from geos_point
back to point
, but safer in a new migration. And no need for migrate_project_geos_point_field
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.
sadly the RenameField
migration doesn't work. It just gives a cryptic error. I assume it's because the old field is a normal sqlite field and the new one is a spatialite gis field, but that's more of a guess.
+ ": " | ||
+ str(geojson_point) | ||
) | ||
continue |
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 this log warning be showing in sentry? otherwise i am afraid we will forget to check when deloying to prod/stage
street_name = models.CharField(null=True, blank=True, max_length=200) | ||
house_number = models.CharField(null=True, blank=True, max_length=10) | ||
zip_code = models.CharField(null=True, blank=True, max_length=20) | ||
|
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.
The properties of the existing geometry is strname
etc, how do we convert between those and the different names you are using here?
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.
good point, I kind of ignored that for now since we don't actually use them anywhere. I've added these to not loose the information of the geojson points already in the database. But these won't be populated for new points at the moment. We'd either need a mapping or decide to get rid of them altogether
project.house_number = properties["hsnr"] | ||
if "plz" in properties: | ||
project.zip_code = properties["plz"] | ||
project.save() |
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.
Not clear where the geometry properties come from in your migration above. Needs docstrings.
|
||
serializer = FakePointSerializer() | ||
data = serializer.to_representation(None) | ||
assert data["point"] == geojson_point |
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.
I would move all fake classes and geojson points outside the tests, since they are hardcoded and re-used, and call them as fixtures from the tests.
@partizipation this PR, introducing django.gis for storing geopoints in the database |
This is a first attempt to move geographical locations from being stored as plain json/geojson to GeoDjango. This will allow us to filter for locations on a database level.
Tasks