Skip to content

Instantly share code, notes, and snippets.

@micahcochran
Created December 31, 2015 17:16
Show Gist options
  • Save micahcochran/42de8723a05d88e5659a to your computer and use it in GitHub Desktop.
Save micahcochran/42de8723a05d88e5659a to your computer and use it in GitHub Desktop.
geosshim.py Attempted Shapely support for Basemap
# Note: This code does NOT work!!!
# Attempt at a shim for Shapely to work with basemap.
# This is to try to use Shapely for the code that need libgeos.
# The code is minimal on purpose.
# add this file into the lib/mpl_toolkits/basemap folder
# in __init__.py change this line:
# import _geoslib
# to:
# import geosshim as _geoslib
from shapely.geometry.base import BaseGeometry as ShapelyBaseGeometry
import shapely.geometry
import numpy
class BaseGeometry(ShapelyBaseGeometry):
# make shapely property a function
def is_valid(self):
return self.is_valid
def fix(self):
pass
# not working quite right for basemap
@property
def boundary(self):
return numpy.array(ShapelyBaseGeometry.boundary)
class Point(BaseGeometry, shapely.geometry.Point):
pass
class LineString(BaseGeometry, shapely.geometry.LineString):
pass
class Polygon(BaseGeometry, shapely.geometry.Polygon):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment