Geospatial Python class to extract vertices inside a polygon - Tutorial

We have to redefine the way we do our geospatial analysis. It is not enough to know the "tool" but to master the "process" if we want to provide spatial solutions for the always bigger geospatial data available. We have done a simple process of extracting vertices from polygons, lines and points inside a polygon in Python, but not a simple and declarative script but as a Python class. 

Tutorial

Scripts

This is the Python code that runs the geospatial class:

from geospatialClass.insidePolygon import extractVertices

#Create an object
insidePoints = extractVertices()

#Open limit layers and definition layers
#Limit layer is allways a polygon
insidePoints.addLimit('basin','../In/modelExtension_v1.shp')
#Layers can be polygons,rivers and points
insidePoints.addLayer('facilities','../In/mineFacilities_v1.shp') #polygon
insidePoints.addLayer('river','../In/riverNetwork_v1.shp') #linestring
insidePoints.addLayer('observation','../In/observationPoints_v1.shp') #points

#Generate point pair array
insidePoints.verticesAsPairArray()

#Export vertices
insidePoints.exportVertices('../Out/verticesInsidePolygon.shp')

Input data

You can download the input data from this link.

1 Comment

Saul Montoya

Saul Montoya es Ingeniero Civil graduado de la Pontificia Universidad Católica del Perú en Lima con estudios de postgrado en Manejo e Ingeniería de Recursos Hídricos (Programa WAREM) de la Universidad de Stuttgart con mención en Ingeniería de Aguas Subterráneas y Hidroinformática.

 

Suscribe to our online newsletter

Subscribe for free newsletter, receive news, interesting facts and dates of our courses in water resources.