Save data to a polygonfield

Asked

Viewed 60 times

0

good night,

I am implementing a project using Django and have the following model:

class ModelExample(models.Model):
    city = models.CharField("Cidade", max_length=100, blank=True)
    state = models.CharField("Estado", max_length=2, blank=True)
    polygon = gis_models.PolygonField(default='POLYGON EMPTY')

and I have the json of the link below: https://maps.googleapis.com/maps/api/geocode/json?address=Mountain+View,+CA&key=AIzaSyD3VO8vvIb1fAuDANRgI3XbpUslKktB0i4

The idea is to always search via pointfields from another model if a particular neighborhood is contained in the city. It would be something like Modelexample.objects.get(polygon__contains=Outromodel.point)

My big question is how to save the json data (node [Geometry][Bounds]) in polygonfield?

1 answer

0

I was able to solve my problem using the app https://github.com/znc-sistemas/django-municipios. With it I have models ready to manipulate data of cities and states of Brazil and it has a shp file ready with ibge data as the geographical coordinates of each city of Brazil. Once imported such file (using the python command Manage.py loaddata filename) just used the Geodjango ready functions that searches for existing streets or not in a city worked correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.