Wednesday, May 23, 2018

Re: geodjango wrong srid when it saves feature

in fact I tried this and problem solved I have no idea why this happened

geom_t = feat.geom.transform(wgs84, clone=True)
geom= GEOSGeometry(geom_t.wkt,4326)

On Wednesday, May 23, 2018 at 7:54:46 PM UTC+4:30, Daniel Germano Travieso wrote:
Hello!

You should probably use the LineString from django.contrib.gis.geos to store Geo objects on the database

Hope it helps.

[]'s
Daniel Germano Travieso
Engenharia da Computação Turma: 013
Unicamp

On Wed, May 23, 2018 at 11:54 AM, Majid Hojati <asd...@gmail.com> wrote:
Hi,
I tried to read data from a shape file and save them into database. well here is my code


lyr = ds[0]
for feat in lyr:
geom_t = feat.geom.transform(wgs84, clone=True)
print(geom_t.wkt)
print(feat.geom.wkt)

name =''
Twoway='1'

data = {
'name': name,
'Twoway': Twoway,
'geom': geom_t.wkb
}
form = Street_Form(data)
if form.is_valid():
savedlocation = form.save()

well it saves and works fine. I printed some of my geometries as wkt before saving to databse and here is the result 

LINESTRING (50.9847540637495 35.8384680697353,50.9850968571006 35.8383655346687)  LINESTRING (50.9847540637495 35.8384680697353,50.9850968571006 35.8383655346687)  

As you can see they are EPSG:4326 and nothing is wrong. 
Here is my model

class str(models.Model):
geom = models.LineStringField(srid=4326)

but when I read data from database they are as following

"LINESTRING(0.000457917485762628 0.000321907544087987,0.000457920236524686 0.000321915031075541)"

the above result is from this query

select st_astext(geom) from public."app_str"

well the geometries are misplaced, where is the problem?why this happens?

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/76979930-39f5-4deb-9c95-dcf3d7f55f97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/167690aa-e363-4789-a115-11026079c2de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment