Import Polygon Data from geojson files into PostGIS using GeoDjango
Asked Answered
F

1

5

Am using GeoDjango with PostGIS as Backend. I have few geojson files with features as following example. GeoDjango has provided information to import shape files and other formats but geojson formats. How do I import these geojson files into DB?

  "features": [
{ "type": "Feature", "properties": { "SubName": "X", "SubSubName": "A" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 70.693828, 37.074496 ], [ 70.693828, 37.074496 ] ] ] } }
,
{ "type": "Feature", "properties": { "SubName": "X", "SubSubName": "B" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 70.502913, 27.065997 ],  [ 70.502913, 27.065997 ] ] ] } }

I have two core requirements:

  1. Load the Subregion polygons on webportal using D3JS Map library
  2. When i have a lat-long, find in which polygon does this point exist and get the SubName & SubSubName from the polygon properties.

It would be great, if there is proper documentation on PostGIS usage & import files for GeoDjango.

Thanks in Advance.

Fattal answered 21/9, 2016 at 12:49 Comment(0)
A
8

Taken from - https://docs.djangoproject.com/en/1.9/ref/contrib/gis/geos/

from django.contrib.gis.geos import GEOSGeometry
# load from geo-json str
pnt = GEOSGeometry('{ "type": "Point", "coordinates": [ 5.000000, 23.000000 ] }')

The geojson can be for anything like polygon, multi-polygon, etc.

Alvinaalvine answered 6/6, 2017 at 2:12 Comment(1)
This answer is not correct. GEOSGeometry is just for storing a geometry, which is only a part of a Feature. By simply importing the geometry (here Point) into the DB, one would completely loose any properties that were assigned to that feature (here SubNameand SubSubName).Oracular

© 2022 - 2024 — McMap. All rights reserved.