예제 #1
0
    def start(self):
        oversize = self.bounds.x0 < -180 - E or self.bounds.x1 > 180 + E or self.bounds.y0 < -90 - E or self.bounds.y1 > 90 + E
        if not self.system:
            if oversize:
                self.system = systems["cartesian"]
            else:
                self.system = systems["spherical"]
        if self.system == systems['spherical']:
            if self.bounds.x0 < -180 + E:
                self.bounds.x0 = -180
            if self.bounds.x1 > 180 - E:
                self.bounds.x1 = 180
            if self.bounds.y0 < -90 + E:
                self.bounds.y0 = -90
            if self.bounds.y1 > 90 - E:
                self.bounds.y1 = 90
        if is_infinit(self.bounds.x0):
            self.bounds.x0 = 0
        if is_infinit(self.bounds.x1):
            self.bounds.x1 = 0
        if is_infinit(self.bounds.y0):
            self.bounds.y0 = 0
        if is_infinit(self.bounds.y1):
            self.bounds.y1 = 0
        if not self.quantization:
            self.quantization = self.bounds.x1 + 1
            self.bounds.x0 = self.bounds.y0 = 0
        [self.kx,
         self.ky] = make_ks(self.quantization, self.bounds.x0, self.bounds.x1,
                            self.bounds.y0, self.bounds.y1)
        self.quant = Quantize(self.bounds.x0, self.bounds.y0, self.kx, self.ky,
                              self.system.distance)
        self.clock = Clock(self.system.ring_area)

        #Convert features to geometries, and stitch together arcs.
        class Topo(Types):
            def __init__(self, ln, id_func, property_transform):
                self.ln = ln
                self.id_func = id_func
                self.property_transform = property_transform

            def Feature(self, feature):
                geometry = feature["geometry"]
                if feature['geometry'] == None:
                    geometry = {}
                if 'id' in feature:
                    geometry['id'] = feature['id']
                if 'properties' in feature:
                    geometry['properties'] = feature['properties']
                return self.geometry(geometry)

            def FeatureCollection(self, collection):
                collection['type'] = "GeometryCollection"
                collection['geometries'] = map(self.Feature,
                                               collection['features'])
                del collection['features']
                return collection

            def GeometryCollection(self, collection):
                collection['geometries'] = map(self.geometry,
                                               collection['geometries'])

            def MultiPolygon(self, multiPolygon):
                multiPolygon['arcs'] = map(
                    lambda poly: map(self.ln.line_closed, poly),
                    multiPolygon['coordinates'])

            def Polygon(self, polygon):
                polygon['arcs'] = map(self.ln.line_closed,
                                      polygon['coordinates'])

            def MultiLineString(self, multiLineString):
                multiLineString['arcs'] = map(self.ln.line_open,
                                              multiLineString['coordinates'])

            def LineString(self, lineString):
                lineString['arcs'] = self.ln.line_open(
                    lineString['coordinates'])

            def geometry(self, geometry):
                if geometry == None:
                    geometry = {}
                else:
                    Types.geometry(self, geometry)
                geometry['id'] = self.id_func(geometry)
                if geometry['id'] == None:
                    del geometry['id']
                properties0 = geometry['properties']
                if properties0:
                    properties1 = {}
                    del geometry['properties']
                    for key0 in properties0:
                        if self.property_transform(properties1, key0,
                                                   properties0[key0]):
                            geometry['properties'] = properties1
                if 'arcs' in geometry:
                    del geometry['coordinates']
                return geometry

        self.topo = Topo(self.ln, self.id_func, self.property_transform)
        AddMessage('looping through ' + str(self.feature_length) +
                   ' features again')
        for db in self.feature_db:
            for i in self.feature_db[db]:
                #AddMessage('on '+str(i))
                self.tweak(self.feature_db[db], i)
예제 #2
0
def clock(features, area):
    cobj = Clock(area)
    features = map(cobj.clock, features)
    return features