Skip to content

Commit

Permalink
added attributes() to projection class
Browse files Browse the repository at this point in the history
  • Loading branch information
gka committed Jan 15, 2012
1 parent 18412a0 commit 2c66fd8
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/polygon/base.py
Expand Up @@ -30,7 +30,7 @@ def __len__(self):
def __getitem__(self, key):
raise NotImplementedError

def addContour(self, contour):
def addContour(self, contour, isHole=False):
raise NotImplementedError

def __and__(self, other):
Expand All @@ -54,4 +54,5 @@ def center(self):
def isInside(self, x, y):
raise NotImplementedError


def svgPath(self):
raise NotImplementedError
24 changes: 22 additions & 2 deletions lib/polygon/poly.py
Expand Up @@ -38,8 +38,8 @@ def __len__(self):
def __getitem__(self, key):
return self.poly[key]

def addContour(self, contour):
self.poly.addContour(contour)
def addContour(self, contour, isHole=False):
self.poly.addContour(contour, isHole)

def __and__(self, other):
from Polygon import Polygon as Poly
Expand All @@ -63,3 +63,23 @@ def center(self):
def isInside(self, x, y):
return self.poly.isInside(x,y)

def svgPath(self):
"""
returns the path string representation of this polygon
"""
ps = ''
pts = self.points[:]
if self.closed:
pts.append(pts[0])
for pt in pts:
if pt.deleted: continue #ignore deleted points
if ps == '': ps = 'M'
else: ps += 'L'
if useInt:
ps += '%d,%d' % (round(pt.x), round(pt.y))
else:
ps += '%.3f,%.3f' % (pt.x, pt.y)
if self.closed:
ps += 'Z' # close path
return ps

13 changes: 9 additions & 4 deletions lib/proj/azimuthal.py
Expand Up @@ -50,12 +50,13 @@ def _truncate(self, x, y):
y1 = self.r + self.r * math.sin(theta)
return (x1,y1)

def world_bounds(self, llbbox=(-180,-90,180,90)):
from gisutils import Bounds2D
def world_bounds(self, bbox, llbbox=(-180,-90,180,90)):
if llbbox == (-180,-90,180,90):
bbox = Bounds2D(width=self.r*2, height=self.r*2)
d = self.r*2
bbox.update((0,0))
bbox.update((d,d))
else:
bbox = super(Azimuthal, self).world_bounds(llbbox)
bbox = super(Azimuthal, self).world_bounds(bbox, llbbox)
return bbox

def sea_shape(self, llbbox=(-180,-90,180,90)):
Expand All @@ -78,6 +79,10 @@ def toXML(self):
def __str__(self):
return 'Proj('+self.name+', lon0=%s, lat0=%s)' % (self.lon0, self.lat0)

@staticmethod
def attributes():
return ['lon0','lat0']




Expand Down
7 changes: 7 additions & 0 deletions lib/proj/base.py
Expand Up @@ -104,6 +104,13 @@ def toXML(self):
p = SVG('proj', id=self.name)
return p

@staticmethod
def attributes():
"""
returns array of attribute names of this projection
"""
return []

@staticmethod
def fromXML(xml):
id = xml['id']
Expand Down
5 changes: 5 additions & 0 deletions lib/proj/conic.py
Expand Up @@ -47,6 +47,11 @@ def toXML(self):
p['lat2'] = str(self.lat2)
return p

@staticmethod
def attributes():
return ['lon0','lat0','lat1','lat2']



class LCC(Conic):
"""
Expand Down
9 changes: 9 additions & 0 deletions lib/proj/cylindrical.py
Expand Up @@ -95,6 +95,10 @@ def toXML(self):
def __str__(self):
return 'Proj('+self.name+', lon0=%s)' % self.lon0

@staticmethod
def attributes():
return ['lon0','flip']

def ll(self, lon, lat):
if self.flip == 1:
return (-lon, -lat)
Expand Down Expand Up @@ -140,6 +144,11 @@ def toXML(self):
p['lat1'] = str(self.lat1)
return p

@staticmethod
def attributes():
return ['lon0','lat1', 'flip']


def __str__(self):
return 'Proj('+self.name+', lon0=%s, lat1=%s)' % (self.lon0, self.lat1)

Expand Down
6 changes: 6 additions & 0 deletions lib/proj/pseudocylindrical.py
Expand Up @@ -18,6 +18,7 @@

from cylindrical import Cylindrical
import math
from math import radians as rad

class PseudoCylindrical(Cylindrical):
def __init__(self, lon0=0.0, flip = 0):
Expand Down Expand Up @@ -247,4 +248,9 @@ def toXML(self):
p = super(Loximuthal, self).toXML()
p['lat0'] = str(self.lat0)
return p

@staticmethod
def attributes():
return ['lon0','lat0','flip']


0 comments on commit 2c66fd8

Please sign in to comment.