I'm trying to use OWSLib to deal with multiple WSF features in python, for now, I'm trying to return all features in sfb WFS that intersects with the specifc feature retrieved in sicar WFS.
from owslib.wfs import WebFeatureService, Authentication
from owslib.fes2 import PropertyIsEqualTo, Intersects
from owslib.etree import etree
auth = Authentication()
auth.verify = False
sicar = WebFeatureService(
url="https://geoserver.car.gov.br/geoserver/sicar/ows", auth=auth, version='2.0.0')
sfb = WebFeatureService(
'http://sistemas.florestal.gov.br/geoserver/ows', version='2.0.0')
car = 'MT-5103700-92A39DC62FDF4D88874F218D41BE1C7F'
filter_car = PropertyIsEqualTo('cod_imovel', car).toXML()
carInfo = sicar.getfeature(typename='sicar:sicar_imoveis_mt',
filter=filter_car, method='post', outputFormat='json')
The code above is working fine, the problem starts when i try to get the Intersects
geom_property = 'geo_area_imovel';
carInfoStr = carInfo.read().decode('utf-8');
geom = json.loads(carInfoStr)['features'][0]['geometry']['coordinates']
#I'm trying to pass the the coordinates list to Intersects, but i tried with other keys of the object and with the xml response, but doesn't wotk as well.
filter_contains = Intersects(geom_property, geom).toXML()
intersected = sfb.getfeature(typename='CNFP_orig:APP_Total_simp',
filter=filter_contains, outputFormat='json', method='post')
The returned errors involve the toXML function, wich depends on the geometry i pass to the intersects, in this case its a string, but need to be the constructor of something of the owslib, but the lib only have Point constructor.
I could pass a point if I could retrieve the centroid of geometry, but I don't now how to do this with this lib. BUT, even the example passed in a official PR is not working.
the PR with example: https://github.com/geopython/OWSLib/pull/780
The error in this code:
Traceback (most recent call last):
File "/home/gabrielubuntu/repos/pygeogis/app.py", line 38, in <module>
filter_contains = Intersects(geom_property, geom).toXML()
File "/home/gabrielubuntu/repos/pygeogis/.venv/lib/python3.10/site-packages/owslib/fes2.py", line 420, in toXML
node.append(self.geometry.toXML())
AttributeError: 'dict' object has no attribute 'toXML'
carinfo
contains JSON and not XML?