O'Reilly logo

Geospatial Development By Example with Python by Pablo Carreira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Importing polygons

Now that we have the basics on how to work with polygons and we know how to represent and store them, we will go back to our app and add the ability to import geospatial files containing polygons. As we did with the points, we will abstract the features into the Python objects and we will also use class inheritance.

First, let's look at the code we already wrote. In the models.py file, we have the PointCollection class:

class PointCollection(object): def __init__(self, file_path=None): """This class represents a group of vector data.""" self.data = [] self.epsg = None if file_path: self.import_data(file_path) def __add__(self, other): self.data += other.data return self def import_data(self, file_path): """Opens an vector file ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required