本文整理汇总了Python中forms.UploadForm.supported_geomtypes方法的典型用法代码示例。如果您正苦于以下问题:Python UploadForm.supported_geomtypes方法的具体用法?Python UploadForm.supported_geomtypes怎么用?Python UploadForm.supported_geomtypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.UploadForm
的用法示例。
在下文中一共展示了UploadForm.supported_geomtypes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_single_shp
# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import supported_geomtypes [as 别名]
def load_single_shp(request):
"""
GET returns a form to upload a zipped shp
POST takes the zip, validates that it is a single-feature poly shp and returns KML
"""
user = request.user
if user.is_anonymous() or not user.is_authenticated():
return HttpResponse('You must be logged in', status=401)
form = UploadForm()
if request.method == 'POST':
form = UploadForm(request.POST, request.FILES)
# Override the defulat form behavior and
# only allow single-feature polygon shps
form.multi_feature = False
form.supported_geomtypes = ['Polygon']
if form.is_valid():
layer = form.handle(request.FILES['file_obj'],user)
g = layer[0].geom
if g.srs:
g.transform_to(4326)
geoms = [g]
t = get_template('loadshp/loadshp.kml')
kml = t.render(Context({'username': user.username, 'geoms': geoms}))
json = simplejson.dumps({'input_kml': kml, 'status':'success'})
# Jquery Form plugin requires that we wrap this in a textarea
# otherwise it mangles the kml
return HttpResponse('<textarea>'+json+'</textarea>',mimetype="text/html")
else:
json = simplejson.dumps({'error_html': form.errors['file_obj'][0], 'status':'errors'})
return HttpResponse('<textarea>'+json+'</textarea>',mimetype="text/html")
elif request.method == 'GET':
return render_to_response('loadshp/upload.html', RequestContext(request,{'form': form,'action':request.path}))
else:
raise Exception("This URL does not support %s requests" % request.method)