Geographic Information Systems Asked on July 28, 2021
Using the Python requests library I need to make a query through an XML to GeoServer which I need to return a GeoTIFF format image. This is the query:
def ParqueNacional(request):
context={}
if request.method=='POST' :
nombre="areaProtegidaParqueNacional"
cantidad=request.POST['cantidad']
prioridad=request.POST['prioridad']
inclusion=request.POST['inclusion']
operador=request.POST['operador']
payload="""
<?xml version="1.0" encoding="UTF-8"?><wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
<ows:Identifier>ras:Jiffle</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>coverage</ows:Identifier>
<wps:Reference mimeType="image/geotiff" xlink:href="http://geoserver/wcs" method="POST">
<wps:Body>
<wcs:GetCoverage service="WCS" version="1.1.1">
<ows:Identifier>pad:"""+ nombre +"""</ows:Identifier>
<wcs:DomainSubset>
<ows:BoundingBox crs="http://www.opengis.net/gml/srs/epsg.xml#32719">
<ows:LowerCorner>225000 6800000</ows:LowerCorner>
<ows:UpperCorner>590000 7100000</ows:UpperCorner>
</ows:BoundingBox>
</wcs:DomainSubset>
<wcs:Output format="image/geotiff"/>
</wcs:GetCoverage>
</wps:Body>
</wps:Reference>
</wps:Input>
<wps:Input>
<ows:Identifier>script</ows:Identifier>
<wps:Data>
<wps:LiteralData> dem=src[0]; dem2=dem""" + operador + str(cantidad) +""" ? 1:0; dest= (dem2); </wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>outputType</ows:Identifier>
<wps:Data>
<wps:LiteralData>INTEGER</wps:LiteralData>
</wps:Data>
</wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
<wps:RawDataOutput mimeType="image/geotiff">
<ows:Identifier>result</ows:Identifier>
</wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>
"""
headers={
"Content-type":"text/xml",
"service":"wcs",
"version":"1.0.0",
"format":"image/geotiff",
}
url='locahost
http = urllib3.PoolManager()
encode=urllib.parse.quote_plus(payload)
with open('core/static/core/img/test.geotiff','wb') as f:
response = requests.post(url , data=payload, headers=headers, auth=("I","pass"), timeout=None, stream=True)
for data in response.iter_content(1024):
f.write(data)
assert(response.status_code==200)
return render(request,"core/ParqueNacional.html",context )
but this is the error that returns me:
<?xml version="1.0" encoding="UTF-8"?><ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows localhost">
<ows:Exception exceptionCode="NoApplicableCode">
<ows:ExceptionText>org.xmlpull.v1.XmlPullParserException: processing instruction can not have PITarget with reserveld xml name (position: START_DOCUMENT seen n <?xml ... @2:11)
processing instruction can not have PITarget with reserveld xml name (position: START_DOCUMENT seen n <?xml ... @2:11) </ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
How can I fix this error?
From the exception, GeoServer doesn't like the format of your XML, I would try changing:
payload="""
<?xml version
to
payload="""<?xml version
Answered by Ian Turton on July 28, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP