def unionFeature(request): try: post_dict = dict(request.POST.copy().iteritems()) layer_id = int(post_dict['layer_id']) featureCollection = json.loads(post_dict['feature']) layer = Shapefile.objects.get(pk=layer_id, created_by=request.user) output = ogr.Geometry(geometryNameToOgrType(layer.geom_type)) for feature in featureCollection['features']: geometry = ogr.CreateGeometryFromJson(json.dumps(feature['geometry'])) feature['geometry'] = None output = output.Union(geometry) output = forceOgrMulti(output, layer.geom_type) featureCollection['features'][0]['geometry'] = json.loads(output.ExportToJson()) response = json.dumps(featureCollection) return HttpResponse(response,content_type="application/json") except: traceback.print_exc() return HttpResponse("")
def eraseFeature(request): try: post_dict = dict(request.POST.copy().iteritems()) featureCollection = json.loads(post_dict['feature']) mask = json.loads(post_dict['mask']) ogrMask = ogr.CreateGeometryFromJson(json.dumps(mask)) layer_id = int(post_dict['layer_id']) layer = Shapefile.objects.get(pk=layer_id, created_by=request.user) for feature in featureCollection['features']: geometry = ogr.CreateGeometryFromJson(json.dumps(feature['geometry'])) output = geometry.Difference(ogrMask) output = forceOgrMulti(output, layer.geom_type) feature['geometry'] = json.loads(output.ExportToJson()) response = json.dumps(featureCollection) return HttpResponse(response,content_type="application/json") except: traceback.print_exc() return HttpResponse("")