def get_unlocked_simple_geometries(request,planid):
    """
    Emulate a WFS service for selecting unlocked geometries.

    This function retrieves all unlocked geometries within a geolevel
    for a given plan. This function is necessary because a traditional
    view could not be used to obtain the geometries in a versioned fashion.

    This method accepts 'version__eq', 'level__eq', and 'geom__eq' URL parameters.

    Parameters:
    request -- An HttpRequest, with the current user.
    planid -- The plan ID from which to get the districts.

    Returns:
    A GeoJSON HttpResponse, describing the unlocked simplified geometries
    """
    note_session_activity(request)

    status = {'type':'FeatureCollection'}

    plan = Plan.objects.filter(id=planid)
    if plan.count() == 1:
        plan = plan[0]
        version = request.POST.get('version__eq', plan.version)
        geolevel = request.POST.get('level__eq', plan.legislative_body.get_geolevels()[0].id)
        geom = request.POST.get('geom__eq', None)
        if geom is not None:
            try:
                wkt = request.POST.get('geom__eq', None)
                geom = GEOSGeometry(wkt)
            # If we can't get a poly, try a linestring
            except GEOSException:
                wkt = request.REQUEST['geom__eq'].replace('POLYGON', 'LINESTRING')
                wkt = wkt.replace('((', '(').replace('))', ')')
                try: 
                    geom = GEOSGeometry(wkt)
                except GEOSException:
                    # If the line doesn't work, just don't return anything
                    geom = None

            # Selection is the geounits that intersects with the drawing tool used:
            # either a lasso, a rectangle, or a point
            selection = Q(geom__intersects=geom)

            # Create a union of locked geometries
            districts = [d.id for d in plan.get_districts_at_version(version, include_geom=True) if d.is_locked]
            locked = District.objects.filter(id__in=districts).collect()

            # Create a simplified locked boundary for fast, but not completely accurate lookups
            # Note: the preserve topology parameter of simplify is needed here
            locked_buffered = locked.simplify(100, True).buffer(100) if locked else None

            # Filter first by geolevel, then selection
            filtered = Geolevel.objects.get(id=geolevel).geounit_set.filter(selection)
            # Assemble the matching features into geojson
            features = []
            for feature in filtered:
                # We want to allow for the selection of a geometry that is partially split
                # with a locked district, so subtract out all sections that are locked
                geom = feature.simple

                # Only perform additional tests if the fast, innacurate lookup passed
                if locked and geom.intersects(locked_buffered):

                    # If a geometry is fully locked, don't add it
                    if feature.geom.within(locked):
                        continue

                    # Overlapping geometries are the ones we need to subtract pieces of
                    if feature.geom.overlaps(locked):
                        # Since this is just for display, do the difference on the simplified geometries
                        geom = geom.difference(locked_buffered)
                        
                features.append({
                    # Note: OpenLayers breaks when the id is set to an integer, or even an integer string.
                    # The id ends up being treated as an array index, rather than a property list key, and
                    # there are some bizarre consequences. That's why the underscore is here.
                    'id': '_%d' % feature.id,
                    'geometry': json.loads(geom.json),
                    'properties': {
                        'name': feature.name,
                        'geolevel_id': geolevel,
                        'id': feature.id
                    }
                })
                    
            status['features'] = features
            return HttpResponse(json.dumps(status),mimetype='application/json')
            
        else:
            status['features'] = []
            status['message'] = _('Geometry is required.')
            
    else:
        status['features'] = []
        status['message'] = _('Invalid plan.')

    return HttpResponse(json.dumps(status),mimetype='application/json')
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/get_unlocked_simple_geometries/original