예제 #1
0
def findFeature(request):
    try:
        shapefile_id = int(request.GET['shapefile_id'])
        latitude = float(request.GET['latitude'])
        longitude = float(request.GET['longitude'])
        shapefile = Shapefile.objects.get(id=shapefile_id)
        pt = Point(longitude, latitude)
        radius = utils.calcSearchRadius(latitude, longitude, 10)
        
        if shapefile.geom_type == "Point":
            query = Feature.objects.filter(geom_point__dwithin=(pt, radius))
        elif shapefile.geom_type in ["LineString", "MultiLineString"]:
            query = Feature.objects.filter(geom_multilinestring__dwithin=(pt, radius))
        elif shapefile.geom_type in ["Polygon", "MultiPolygon"]:
            query = Feature.objects.filter(geom_multipolygon__dwithin=(pt, radius))
        elif shapefile.geom_type == "MultiPoint":
            query = Feature.objects.filter(geom_multipoint__dwithin = (pt, radius))
        #elif shapefile.geom_type == "GeometryCollection":
            #query = Feature.objects.filter(geom_geometrycollection__dwithin=(pt,radius))
        else:
            print "Unsupported geometry: " + shapefile.geom_type
            return HttpResponse("")
        if query.count() != 1:
            return HttpResponse("")
        
        feature = query.all()[0]
        return HttpResponse("/shape-editor/editFeature/" +
                    str(shapefile_id)+ "/" + str(feature.id))
    except:
        traceback.print_exc()
        return HttpResponse("")
예제 #2
0
def findFeature(request):

    try:
        # TODO: fix this so that it works as in the book
        # may need to switch to PostGIS

        shapefile_id = int(request.GET['shapefile_id'])
        latitude = float(request.GET['latitude'])
        longitude = float(request.GET['longitude'])

        shapefile = Shapefile.objects.get(id=shapefile_id)

        pt = django.contrib.gis.geos.Point(longitude, latitude)
        radius = utils.calcSearchRadius(latitude, longitude, 100)

        # Create a circle polygon. TODO check what this is really doing.
        circleGeom = pt.buffer(radius)

        if shapefile.geom_type == "Point":
            query = Feature.objects.filter(geom_point__within=circleGeom)

        elif shapefile.geom_type in ["LineString", "MultiLineString"]:
            query = Feature.objects.filter(
                geom_multilinestring__dwithin=(pt, radius))
            print query

        elif shapefile.geom_type in ["Polygon", "MultiPolygon"]:
            print 'its here'
            #query = Feature.objects.filter ( geom_multipolygon__contains = pt  )
            query = Feature.objects.filter(geom_multipolygon__dwithin=(pt,
                                                                       radius))

        elif shapefile.geom_type == "Multipoint":
            query = Feature.objects.filter(geom_multipoint__within=circleGeom)

        elif shapefile.geom_type == "GeometryCollection":
            query = Feature.objects.filter(
                geom_geometryCollection__contains=circleGeom)

        else:
            print "Unsupported GEometry: " + shapefile.geom_type
            return HttpResponse("")

        if query.count() != 1:
            print 'oh dear: ' + str(query.count())
            return HttpResponse("")

        feature = query.all()[0]
        return HttpResponse("/shape-editor/editFeature/" + str(shapefile_id) +
                            "/" + str(feature.id))

    except:
        traceback.print_exc()
        return HttpResponse("")
예제 #3
0
def findFeature (request) : 

    try: 
       # TODO: fix this so that it works as in the book
       # may need to switch to PostGIS

        shapefile_id = int ( request.GET ['shapefile_id'] )
        latitude   = float ( request.GET ['latitude'] ) 
        longitude  = float ( request.GET ['longitude'] ) 

        shapefile = Shapefile.objects.get (id = shapefile_id ) 

        pt = django.contrib.gis.geos.Point (longitude, latitude)
        radius = utils.calcSearchRadius ( latitude, longitude , 100) 

        # Create a circle polygon. TODO check what this is really doing.
        circleGeom = pt.buffer ( radius )

        if shapefile.geom_type == "Point":
            query = Feature.objects.filter ( geom_point__within  =  circleGeom)

        elif shapefile.geom_type in ["LineString", "MultiLineString"]:
            query = Feature.objects.filter ( geom_multilinestring__dwithin =( pt, radius))
            print query



        elif shapefile.geom_type in ["Polygon", "MultiPolygon"]:
            print 'its here'
            #query = Feature.objects.filter ( geom_multipolygon__contains = pt  )
            query = Feature.objects.filter ( geom_multipolygon__dwithin =( pt, radius))

        elif shapefile.geom_type == "Multipoint":
            query = Feature.objects.filter ( geom_multipoint__within = circleGeom)

        elif shapefile.geom_type == "GeometryCollection":
            query = Feature.objects.filter ( geom_geometryCollection__contains = circleGeom)

        else:
            print "Unsupported GEometry: " + shapefile.geom_type
            return HttpResponse ("")

        if query.count () != 1:
            print 'oh dear: ' + str (query.count () ) 
            return HttpResponse ("")
   
        feature = query.all () [0] 
        return HttpResponse ("/shape-editor/editFeature/" + str (shapefile_id) + "/" + str (feature.id )  )
 
    except:
        traceback.print_exc()
        return HttpResponse("")
예제 #4
0
파일: views.py 프로젝트: kakaTyx/geoedit
def findFeature(request):
    """ See if the user clicked on a feature in our shapefile.
    """
    try:
        shapefile_id = int(request.GET['shapefile_id'])
        latitude     = float(request.GET['latitude'])
        longitude    = float(request.GET['longitude'])

        shapefile = Shapefile.objects.get(id=shapefile_id)
        pt = Point(longitude, latitude)
        radius = utils.calcSearchRadius(latitude, longitude, 100) # 100 meters.

        if shapefile.geom_type == "Point":
            query = Feature.objects.filter(
                geom_singlepoint__dwithin=(pt, radius))
        elif shapefile.geom_type in ["LineString", "MultiLineString"]:
            query = Feature.objects.filter(
                geom_multilinestring__dwithin=(pt, radius))
        elif shapefile.geom_type in ["Polygon", "MultiPolygon"]:
            query = Feature.objects.filter(
                geom_multipolygon__dwithin=(pt, radius))
        elif shapefile.geom_type == "MultiPoint":
            query = Feature.objects.filter(
                geom_multipoint__dwithin=(pt, radius))
        elif shapefile.geom_type == "GeometryCollection":
            query = feature.objects.filter(
                geom_geometrycollection__dwithin=(pt, radius))
        else:
            print "Unsupported geometry: " + feature.geom_type
            return ""

        if query.count() != 1:
            # We don't have exactly one hit -> ignore the click.
            return HttpResponse("")

        # Success!  Redirect the user to the "edit" view for the selected
        # feature.

        feature = query.all()[0]
        return HttpResponse("/shape-editor/editFeature/" +\
                            str(shapefile_id) + "/" + str(feature.id))
    except:
        traceback.print_exc()
        return HttpResponse("")
예제 #5
0
def findFeature(request):
    try:
        shapefile_id = int(request.GET['shapefile_id'])
        latitude = float(request.GET['latitude'])
        longitude = float(request.GET['longitude'])

        shapefile = Shapefile.objects.get(id=shapefile_id)
        pt = Point(longitude, latitude)
        radius = utils.calcSearchRadius(latitude, longitude, 100)

        if shapefile.geom_type == "Point":
            query = Feature.objects.filter(geom_point__dwithin=(pt, radius))
        elif shapefile.geom_type in ["LineString", "MultiLineString"]:
            query = Feature.objects.filter(
                geom_multilinestring__dwithin=(pt, radius))
        elif shapefile.geom_type in ["Polygon", "MultiPolygon"]:
            query = Feature.objects.filter(geom_multipolygon__dwithin=(pt,
                                                                       radius))
        elif shapefile.geom_type == "MultiPoint":
            query = Feature.objects.filter(geom_multipoint__dwithin=(pt,
                                                                     radius))
        elif shapefile.geom_type == "GeometryCollection":
            query = Feature.objects.filter(
                geom_geometrycollection__dwithin=(pt, radius))
        else:
            print "Unsupported geometry: " + shapefile.geom_type
            return HttpResponse("")

        if query.count() != 1:
            return HttpResponse("")

        feature = query.all()[0]
        return HttpResponse("/shape-editor/editFeature/" + str(shapefile_id) +
                            "/" + str(feature.id))
    except:
        traceback.print_exc()
        return HttpResponse("")