added geo module, with region supporting gis data
This commit is contained in:
31
README.md
31
README.md
@@ -21,3 +21,34 @@ python migrate
|
||||
```
|
||||
- Start server in development mode: `python manage.py runserver`
|
||||
|
||||
|
||||
## Load Geo data
|
||||
Import geodata
|
||||
|
||||
```python
|
||||
import os
|
||||
from geo.models import Region
|
||||
from django.contrib.gis.geos import GeometryCollection, GEOSGeometry
|
||||
import json
|
||||
from django.contrib.gis.geos import MultiPolygon
|
||||
|
||||
path='gadm36_ESP_1.json'
|
||||
|
||||
feature_collection = json.loads(open(path).read())
|
||||
for feature in feature_collection['features']:
|
||||
geom = GEOSGeometry(str(feature['geometry']))
|
||||
if feature['geometry']['type'] == "MultiPolygon":
|
||||
poly_list = []
|
||||
for poly in geom:
|
||||
poly_list.append(poly)
|
||||
print(poly_list)
|
||||
else:
|
||||
poly_list = geom
|
||||
|
||||
geom_geos = MultiPolygon(poly_list)
|
||||
|
||||
name = feature['properties']['NAME_1']
|
||||
region = Region.objects.create(name=name,geo=geom_geos)
|
||||
region.save()
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user