I have polygons defined in KML files just like this one, which I can easily parse. Example:
<Polygon><outerBoundaryIs><LinearRing><coordinates>
-91.463940,40.372660,0
-91.483790,40.379440,0
-91.493780,40.392410,0
</coordinates></LinearRing></outerBoundaryIs></Polygon>
I would like to run queries on a postgis table and clip all lines that intersect this polygon. Segments of the lines within the polygon should be deleted. Something like this:
____
___|poly|___line
___| |___line
|____|
Here's the table structure:
Column | Type
--------------+---------------
ogc_fid | integer
wkb_geometry | geometry
id | numeric(8,0)
ele | numeric(12,3)
Is this possible?
What would a query look like?
I assume I need to express the polygon in WKT format and use the documented ST_Intersects method, but I'm not sure how to put this together and modify the geometries.
Can this be done with PyQGIS?
I've loaded my kml file as a QgsVectorLayer, I can access the polygon feature and I can check if it intersects a rectangle:
l = QgsVectorLayer(sys.argv[1], "REGION", "ogr")
r = QgsRectangle(x1,y1,x2,y2)
for feature in l.getFeatures():
if (feature.geometry().intersects(r)):
return True