0

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."

I tried the with List also, but I am getting the same error.

0
    def BuildingCoordinates(request):
        final_coordinates = []
        parcel = Parcel.objects.filter(objectid="22520").values()
        geojson = parcel[0]['geom'].geojson
        ast_format = ast.literal_eval(geojson)
        data = ast_format['coordinates'][0][0]
        poly_california = Polygon(data, srid=3492)
        poly_gps = poly_california.transform(4326, clone=True)
        pnt = GEOSGeometry(poly_gps)
        building = Primary.objects.filter(geom__contained=pnt).values()
        build_geo = building[0]['geom'].geojson
        build_format = ast.literal_eval(build_geo)
        build_coords = build_format['coordinates'][0]
        return HttpResponse(build_coords,content_type='application/json')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.