There is a way to coerce the input to 2d. It's not pretty, but it works.

from django.contrib.gis.geos.prototypes.io import wkt_w
wkt = wkt_w(dim=2).write(input_geom).decode()
geom = GEOSGeometry(wkt, srid=4674)

Imagine that you get input_geom from somewhere. In our case it was coming
from a KML upload. We forced it to 2d using that snippet of code.


On Mon, Dec 19, 2016 at 9:51 AM, <[email protected]> wrote:

> Jason: when you say create 2 geometry types one with 2 dimensions etc...
> how do you specify how many dimensions to have?
> Because I created the field in this way:
>
> geom = models.MultiPolygonField(geography=True, spatial_index=True)
>
> and let the Django migration do the job, but I don't know how to specify
> that it's a 3D field.
>
> Thanks
>
> On Tuesday, 8 March 2016 16:34:35 UTC, Jason wrote:
>>
>> I had a similar issue when uploading a kml to geojson conversion to
>> postgis using geodjango.  There is no efficient way to do it in Django, so
>> I ended up doing a workaround
>>
>>
>>    - Create two geometry types, one with dims=2 and other with dims=3.
>>    Allow both to be null and set default to null
>>    - When updating, check the geometry dimension via GEOSGeometry.hasz
>>    
>> <https://docs.djangoproject.com/en/1.9/ref/contrib/gis/geos/#django.contrib.gis.geos.GEOSGeometry.hasz>.
>>    If the return is 2, save the geom in the 2D field, otherwise save to the 
>> 3D
>>
>> You can create a save/retrieve method on the model to handle this for you.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/073345f1-0a70-4645-9c87-577c89b9a511%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/073345f1-0a70-4645-9c87-577c89b9a511%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
George R. C. Silva
Sigma Geosistemas LTDA
----------------------------
http://www.sigmageosistemas.com.br/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGyPVTsF1CYmw5gushj8Ky7DLV%3DMRrpf01qFBEY1bUFWtE07mg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to