1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Why my contained Query doesnot work in spatial coordinates in GeoDjango?

Discussion in 'Programming/Internet' started by Manikanta, Oct 8, 2018.

  1. Manikanta

    Manikanta Guest

    These are my Models. I imported the shapefiles to this Models

    class Parcel(models.Model):
    objectid = models.BigIntegerField()
    apn = models.CharField(max_length=80)
    lot_size = models.BigIntegerField()
    neibrhc = models.CharField(max_length=80)
    street_nbr = models.CharField(max_length=80)
    street_nam = models.CharField(max_length=80)
    city = models.CharField(max_length=80)
    zip = models.BigIntegerField()
    tra = models.CharField(max_length=80)
    subdivisio = models.CharField(max_length=80)
    lot = models.CharField(max_length=80)
    landuse = models.CharField(max_length=80)
    lu_general = models.CharField(max_length=80)
    lu_specif = models.CharField(max_length=80)
    lu_detail = models.CharField(max_length=80)
    lu_use = models.CharField(max_length=80)
    lu_sec_use = models.CharField(max_length=80)
    area = models.FloatField()
    perimeter = models.FloatField()
    shape_are = models.FloatField()
    shape_len = models.FloatField()
    geom = models.MultiPolygonField(srid=3492)

    def __str__(self):
    return 'City: %s' % self.city

    class Primary(models.Model):
    id = models.CharField(max_length=12, primary_key=True)
    address = models.CharField(max_length=30)
    city = models.CharField(max_length=30)
    zip = models.CharField(max_length=10)
    state = models.CharField(max_length=2)
    unit = models.CharField(max_length=13)
    primpgon = models.BigIntegerField()
    numpgons = models.BigIntegerField()
    x = models.FloatField()
    y = models.FloatField()
    censusbloc = models.CharField(max_length=15)
    objectid = models.BigIntegerField()
    geom = models.MultiPolygonField(srid=4326)




    from django.contrib.gis.geos import Polygon
    parcel = Parcel.objects.filter(objectid="22520").values()
    geojson = parcel[0]['geom'].geojson
    format_l = ast.literal_eval(geojson)
    coordinates_data = format_l['coordinates'][0][0]

    poly = Polygon(coordinates_data, srid=3492)
    poly_parcel = poly.transform(4326, clone=True)
    polygon = poly_parcel.coords
    print(polygon)


    I define the Polygon as below

    (((-121.49440799279022, 38.55725848782723),
    (-121.49438844924772, 38.557303481514126),
    (-121.4943760310021, 38.5573320694682),
    (-121.49436263531841, 38.557362909896675),
    (-121.49402385986245, 38.557269114460084),
    (-121.49406987333441, 38.55716268909225),
    (-121.49440799279022, 38.55725848782723)),)


    My Aim is I want to locate the Primary data within the Parcel Data. So I tried this.

    Primary.objects.filter(geom__contains=polygon).values()
    #and also tried with contained lookup
    Primary.objects.filter(geom__contained=polygon).values()


    When I try this querysets it throws the "ValueError: Cannot use object with type tuple for a spatial lookup parameter."

    Even I try the with List also, Even though I am getting the same error

    Can Anyone Suggest me. What was my mistake.

    Login To add answer/comment
     

Share This Page