Esempio n. 1
0
def topology(objects,
             stitchPoles=True,
             quantization=1e4,
             id_key='id',
             property_transform=property_transform,
             system=False,
             simplify=False):
    ln = Line(quantization)
    id_func = lambda x: x[id_key]
    if simplify:
        objects = simplify_object(objects, simplify)
    [x0, x1, y0, y1] = bound(objects)

    oversize = x0 < -180 - E or x1 > 180 + E or y0 < -90 - E or y1 > 90 + E
    if not system:
        if oversize:
            system.name = systems["cartesian"]
        else:
            system = systems["spherical"]
    if system.name == 'spherical':
        if oversize:
            raise Exception(u"spherical coordinates outside of [±180°, ±90°]")
        if stitchPoles:
            stitch(objects)
            [x0, x1, y0, y1] = bound(objects)
        if x0 < -180 + E:
            x0 = -180
        if x1 > 180 - E:
            x1 = 180
        if y0 < -90 + E:
            y0 = -90
        if y1 > 90 - E:
            y1 = 90
    if is_infinit(x0):
        x0 = 0
    if is_infinit(x1):
        x1 = 0

    if is_infinit(y0):
        y0 = 0
    if is_infinit(y1):
        y1 = 0
    [kx, ky] = make_ks(quantization, x0, x1, y0, y1)
    if not quantization:
        quantization = x1 + 1
        x0 = y0 = 0

    class findEmax(Types):
        def __init__(self, obj):
            self.emax = 0
            self.obj(obj)

        def point(self, point):
            x1 = point[0]
            y1 = point[1]
            x = ((x1 - x0) * kx)
            y = ((y1 - y0) * ky)
            ee = system.distance(x1, y1, x / kx + x0, y / ky + y0)
            if ee > self.emax:
                self.emax = ee
            point[0] = int(x)
            point[1] = int(y)

    finde = findEmax(objects)
    emax = finde.emax
    clock(objects, system.ring_area)

    class find_coincidences(Types):
        def line(self, line):
            for point in line:
                lines = ln.arcs.coincidence_lines(point)
                if not line in lines:
                    lines.append(line)

    fcInst = find_coincidences(objects)
    polygon = lambda poly: map(ln.line_closed, poly)

    #Convert features to geometries, and stitch together arcs.
    class make_topo(Types):
        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(polygon, multiPolygon['coordinates'])

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

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

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

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

    make_topo_inst = make_topo(objects)
    return {
        'type': "Topology",
        'bbox': [x0, y0, x1, y1],
        'transform': {
            'scale': [1.0 / kx, 1.0 / ky],
            'translate': [x0, y0]
        },
        'objects': make_topo_inst.outObj,
        'arcs': ln.get_arcs()
    }
Esempio n. 2
0
def topology(objects, stitch_poles=True, verbose=True, e_max=0, coordinate_system=None, object_name='name',
             id_key='id', quantization_factor=1e4, property_transform=None):

    id_ = lambda d: d[id_key]

    if property_transform is None:
        def property_transform(outprop, key, inprop):
            outprop[key] = inprop
            return True

    stitch_poles = True
    verbose = False
    e_max = 0
    object_name = 'name'
    if coordinate_system:
        system = systems[coordinate_system]

    if objects.has_key('type') and objects['type'] == 'FeatureCollection':
        objects = {object_name: objects}
    ln = Line(quantization_factor)

    [x0, x1, y0, y1] = bound(objects)

    oversize = x0 < -180 - E or x1 > 180 + E or y0 < -90 - E or y1 > 90 + E
    if coordinate_system is None:
        if oversize:
            system = systems["cartesian"]
        else:
            system = systems["spherical"]
        coordinate_system = system.name

    if coordinate_system == 'spherical':
        if oversize:
            raise Exception(u"spherical coordinates outside of [±180°, ±90°]")
        if stitch_poles:
            stitch(objects)
            [x0, x1, y0, y1] = bound(objects)
        if x0 < -180 + E:
            x0 = -180
        if x1 > 180 - E:
            x1 = 180
        if y0 < -90 + E:
            y0 = -90
        if y1 > 90 - E:
            y1 = 90

    if is_infinit(x0):
        x0 = 0
    if is_infinit(x1):
        x1 = 0

    if is_infinit(y0):
        y0 = 0
    if is_infinit(y1):
        y1 = 0

    logging.debug("{}".format([x0, y0, x1, y1]))

    kx, ky = make_ks(quantization_factor, x0, x1, y0, y1)
    if not quantization_factor:
        quantization_factor = x1 + 1
        x0 = y0 = 0

    class FindEmax(types):
        def __init__(self, obj):
            self.emax = 0
            self.obj = obj

        def point(self, point):
            x1 = point[0]
            y1 = point[1]
            x = ((x1 - x0) * kx)
            y = ((y1 - y0) * ky)
            ee = system['distance'](x1, y1, x / kx + x0, y / ky + y0)
            if ee > self.emax:
                self.emax = ee
            point[0] = int(x)
            point[1] = int(y)

    finde = FindEmax(objects)
    e_max = finde.emax
    clock(objects, system.ring_area)

    class findCoincidences(types):
        def line(self, line):
            for point in line:
                lines = ln.arcs.coincidenceLines(point)
                if not line in lines:
                    lines.append(line)

    fcInst = findCoincidences(objects)
    polygon = lambda poly: map(ln.lineClosed, poly)

    #Convert features to geometries, and stitch together arcs.
    class makeTopo(types):
        def Feature(self, feature):
            geometry = feature["geometry"]
            if feature['geometry'] == None:
                geometry = {}
            if feature.has_key('id'):
                geometry['id'] = feature['id']
            if feature.has_key('properties'):
                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(polygon, multiPolygon['coordinates'])

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

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

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

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

    makeTopoInst = makeTopo(objects)
    return {
        'type': "Topology",
        'transform': {
            'scale': [1.0 / kx, 1.0 / ky],
            'translate': [x0, y0]
        },
        'objects': makeTopoInst.outObj,
        'arcs': ln.getArcs()
    }
Esempio n. 3
0
def topology (objects, stitchPoles=True,quantization=1e4,id_key='id',property_transform=property_transform,system = False,simplify=False):
    ln = Line(quantization)
    id_func = lambda x:x.get(id_key)
    if simplify:
        objects = simplify_object(objects,simplify)
    [x0,x1,y0,y1]=bound(objects)

    oversize = x0 < -180 - E or x1 > 180 + E or y0 < -90 - E or y1 > 90 + E
    if not system:
        if oversize:
            system =systems["cartesian"]
        else:
            system = systems["spherical"]
    if system.name == 'spherical':
        if oversize:
            raise Exception(u"spherical coordinates outside of [±180°, ±90°]")
        if stitchPoles:
            stitch(objects)
            [x0,x1,y0,y1]=bound(objects)
        if x0 < -180 + E:
            x0 = -180
        if x1 > 180 - E:
            x1 = 180
        if y0 < -90 + E:
            y0 = -90
        if y1 > 90 - E:
            y1 = 90;
    if is_infinit(x0):
        x0 = 0
    if is_infinit(x1):
        x1 = 0;

    if is_infinit(y0):
        y0 = 0;
    if is_infinit(y1):
        y1 = 0;
    [kx,ky]=make_ks(quantization,x0,x1,y0,y1)
    if not quantization:
        quantization = x1 + 1
        x0 = y0 = 0

    class findEmax(Types):
        def __init__(self,obj):
            self.emax=0
            self.obj(obj)
        def point(self,point):
            x1 = point[0]
            y1 = point[1]
            x = ((x1 - x0) * kx)
            y =((y1 - y0) * ky)
            ee = system.distance(x1, y1, x / kx + x0, y / ky + y0)
            if ee > self.emax:
                self.emax = ee
            point[0] = int(x)
            point[1] = int(y)
    finde=findEmax(objects)
    emax = finde.emax
    clock = Clock(system.ring_area)
    clock.clock(objects)
    class find_coincidences(Types):
        def line(self,line):
            for point in line:
                lines = ln.arcs.coincidence_lines(point)
                if not line in lines:
                    lines.append(line)
    fcInst = find_coincidences(objects)
    polygon = lambda poly:map(ln.line_closed,poly)
    #Convert features to geometries, and stitch together arcs.
    class make_topo(Types):
        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(polygon,multiPolygon['coordinates'])
        def Polygon(self,polygon):
             polygon['arcs'] = map(ln.line_closed,polygon['coordinates'])
        def MultiLineString(self,multiLineString):
            multiLineString['arcs'] = map(ln.line_open,multiLineString['coordinates'])
        def LineString(self,lineString):
            lineString['arcs'] = ln.line_open(lineString['coordinates'])
        def geometry(self,geometry):
            if geometry == None:
                geometry = {};
            else:
                Types.geometry(self,geometry)
            geometry['id'] = id_func(geometry)
            if geometry['id'] == None:
                del geometry['id']
            properties0 = geometry['properties']
            if properties0:
                properties1 = {}
                del geometry['properties']
                for key0 in properties0:
                    if property_transform(properties1, key0, properties0[key0]):
                        geometry['properties'] = properties1
            if 'arcs' in geometry:
                del geometry['coordinates']
            return geometry;
    make_topo_inst = make_topo(objects)
    return {
        'type': "Topology",
        'bbox': [x0, y0, x1, y1],
        'transform': {
            'scale': [1.0 / kx, 1.0 / ky],
            'translate': [x0, y0]
        },
        'objects': make_topo_inst.outObj,
        'arcs': ln.get_arcs()
    }
Esempio n. 4
0
def topology(objects, options=False):
    Q = 1e4
    # precision of quantization
    id = lambda d: d['id']

    def propertyTransform(outprop, key, inprop):
        outprop[key] = inprop
        return True

    stitchPoles = True
    verbose = False
    emax = 0
    system = False
    objectName = 'name'
    if type(options) == type({}):
        if options.has_key('verbose'):
            verbose = not not options['verbose']
        if options.has_key('stitch-poles'):
            stitchPoles = not not options["stitch-poles"]
        if options.has_key('coordinate-system'):
            system = systems[options["coordinate-system"]]
        if options.has_key('quantization'):
            Q = float(options["quantization"])
        if options.has_key('id'):
            id = options['id']
        if options.has_key('property-transform'):
            propertyTransform = options["property-transform"]
        if options.has_key('name'):
            objectName = options['name']
    if objects.has_key('type') and objects['type'] == 'FeatureCollection':
        objects = {objectName: objects}
    ln = Line(Q)

    [x0, x1, y0, y1] = bound(objects)

    oversize = x0 < -180 - e or x1 > 180 + e or y0 < -90 - e or y1 > 90 + e
    if not system:
        if oversize:
            system = systems["cartesian"]
        else:
            system = systems["spherical"]
        if type(options) == type({}):
            options["coordinate-system"] = system['name']
    if system == systems['spherical']:
        if oversize:
            raise Exception(u"spherical coordinates outside of [±180°, ±90°]")
        if stitchPoles:
            stitch(objects)
            [x0, x1, y0, y1] = bound(objects)
        if x0 < -180 + e:
            x0 = -180
        if x1 > 180 - e:
            x1 = 180
        if y0 < -90 + e:
            y0 = -90
        if y1 > 90 - e:
            y1 = 90
    if isInfinit(x0):
        x0 = 0
    if isInfinit(x1):
        x1 = 0

    if isInfinit(y0):
        y0 = 0
    if isInfinit(y1):
        y1 = 0
    [kx, ky] = makeKs(Q, x0, x1, y0, y1)
    if not Q:
        Q = x1 + 1
        x0 = y0 = 0

    class findEmax(types):
        def __init__(self, obj):
            self.emax = 0
            self.obj(obj)

        def point(self, point):
            x1 = point[0]
            y1 = point[1]
            x = ((x1 - x0) * kx)
            y = ((y1 - y0) * ky)
            ee = system['distance'](x1, y1, x / kx + x0, y / ky + y0)
            if ee > self.emax:
                self.emax = ee
            point[0] = int(x)
            point[1] = int(y)

    finde = findEmax(objects)
    emax = finde.emax
    clock(objects, system['ringArea'])

    class findCoincidences(types):
        def line(self, line):
            for point in line:
                lines = ln.coincidences.get(point)
                if not line in lines:
                    lines.append(line)

    fcInst = findCoincidences(objects)
    polygon = lambda poly: map(ln.lineClosed, poly)

    #Convert features to geometries, and stitch together arcs.
    class makeTopo(types):
        def Feature(self, feature):
            geometry = feature["geometry"]
            if feature['geometry'] == None:
                geometry = {}
            if feature.has_key('id'):
                geometry['id'] = feature['id']
            if feature.has_key('properties'):
                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(polygon, multiPolygon['coordinates'])

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

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

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

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

    makeTopoInst = makeTopo(objects)
    return {
        'type': "Topology",
        'bbox': [x0, y0, x1, y1],
        'transform': {
            'scale': [1.0 / kx, 1.0 / ky],
            'translate': [x0, y0]
        },
        'objects': makeTopoInst.outObj,
        'arcs': ln.getArcs()
    }
Esempio n. 5
0
def topology (objects, options=False):
	Q = 1e4; # precision of quantization
	id = lambda d:d['id']
	def propertyTransform (outprop, key, inprop):
		outprop[key]=inprop
		return True
	stitchPoles = True
	verbose = False
	emax = 0
	system = False
	objectName = 'name'
	if type(options)==type({}):
		if options.has_key('verbose'):
			verbose = not not options['verbose']
		if options.has_key('stitch-poles'):
			stitchPoles = not not options["stitch-poles"]
		if options.has_key('coordinate-system'):
			system = systems[options["coordinate-system"]]
		if options.has_key('quantization'):
			Q = float(options["quantization"])
		if options.has_key('id'):
			id = options['id']
		if options.has_key('property-transform'):
			propertyTransform = options["property-transform"]
		if options.has_key('name'):
			objectName = options['name']
	if objects.has_key('type') and objects['type']=='FeatureCollection':
		objects = {objectName:objects}
	ln = Line(Q)
	
	
	[x0,x1,y0,y1]=bound(objects)
	
	oversize = x0 < -180 - e or x1 > 180 + e or y0 < -90 - e or y1 > 90 + e
	if not system:
		if oversize:
			system = systems["cartesian"]
		else:
			system = systems["spherical"]
		if type(options)==type({}):
			options["coordinate-system"] = system['name']
	if system == systems['spherical']:
		if oversize:
			raise Exception(u"spherical coordinates outside of [±180°, ±90°]")
		if stitchPoles:
			stitch(objects)
			[x0,x1,y0,y1]=bound(objects)
		if x0 < -180 + e:
			x0 = -180
		if x1 > 180 - e:
			x1 = 180
		if y0 < -90 + e:
			y0 = -90
		if y1 > 90 - e:
			y1 = 90;
	if isInfinit(x0):
		x0 = 0
	if isInfinit(x1):
		x1 = 0;

	if isInfinit(y0):
		y0 = 0;
	if isInfinit(y1):
		y1 = 0;
	[kx,ky]=makeKs(Q,x0,x1,y0,y1)
	if not Q:
		Q = x1 + 1
		x0 = y0 = 0
	class findEmax(types):
		def __init__(self,obj):
			self.emax=0
			self.obj(obj)
		def point(self,point):
			x1 = point[0]
			y1 = point[1]
			x = ((x1 - x0) * kx)
			y =((y1 - y0) * ky)
			ee = system['distance'](x1, y1, x / kx + x0, y / ky + y0)
			if ee > self.emax:
				self.emax = ee
			point[0] = int(x)
			point[1] = int(y)
	finde=findEmax(objects)
	emax = finde.emax
	clock(objects,system['ringArea'])
	class findCoincidences(types):
		def line(self,line):
			for point in line:
				lines = ln.coincidences.get(point)
				if not line in lines:
					lines.append(line)
	fcInst = findCoincidences(objects)
	polygon = lambda poly:map(ln.lineClosed,poly)
	#Convert features to geometries, and stitch together arcs.
	class makeTopo(types):
		def Feature (self,feature):
			geometry = feature["geometry"]
			if feature['geometry'] == None:
				geometry = {};
			if feature.has_key('id'):
				geometry['id'] = feature['id']
			if feature.has_key('properties'):
				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(polygon,multiPolygon['coordinates'])
		def Polygon(self,polygon):
			 polygon['arcs'] = map(ln.lineClosed,polygon['coordinates'])
		def MultiLineString(self,multiLineString):
			multiLineString['arcs'] = map(ln.lineOpen,multiLineString['coordinates'])
		def LineString(self,lineString):
			lineString['arcs'] = ln.lineOpen(lineString['coordinates'])
		def geometry(self,geometry):
			if geometry == None:
				geometry = {};
			else:
				types.geometry(self,geometry)
			geometry['id'] = id(geometry)
			if geometry['id'] == None:
				del geometry['id']
			properties0 = geometry['properties']
			if properties0:
				properties1 = {}
				del geometry['properties']
				for key0 in properties0:
					if propertyTransform(properties1, key0, properties0[key0]):
						geometry['properties'] = properties1
			if geometry.has_key('arcs'):
				del geometry['coordinates']
			return geometry;
	makeTopoInst = makeTopo(objects)
	return {
		'type': "Topology",
		'bbox': [x0, y0, x1, y1],
		'transform': {
			'scale': [1.0 / kx, 1.0 / ky],
			'translate': [x0, y0]
		},
		'objects': makeTopoInst.outObj,
		'arcs': ln.getArcs()
	}
Esempio n. 6
0
def topology(objects,
             stitch_poles=True,
             verbose=True,
             e_max=0,
             coordinate_system=None,
             object_name='name',
             id_key='id',
             quantization_factor=1e4,
             property_transform=None):

    id_ = lambda d: d[id_key]

    if property_transform is None:

        def property_transform(outprop, key, inprop):
            outprop[key] = inprop
            return True

    stitch_poles = True
    verbose = False
    e_max = 0
    object_name = 'name'
    if coordinate_system:
        system = systems[coordinate_system]

    if objects.has_key('type') and objects['type'] == 'FeatureCollection':
        objects = {object_name: objects}
    ln = Line(quantization_factor)

    [x0, x1, y0, y1] = bound(objects)

    oversize = x0 < -180 - E or x1 > 180 + E or y0 < -90 - E or y1 > 90 + E
    if coordinate_system is None:
        if oversize:
            system = systems["cartesian"]
        else:
            system = systems["spherical"]
        coordinate_system = system.name

    if coordinate_system == 'spherical':
        if oversize:
            raise Exception(u"spherical coordinates outside of [±180°, ±90°]")
        if stitch_poles:
            stitch(objects)
            [x0, x1, y0, y1] = bound(objects)
        if x0 < -180 + E:
            x0 = -180
        if x1 > 180 - E:
            x1 = 180
        if y0 < -90 + E:
            y0 = -90
        if y1 > 90 - E:
            y1 = 90

    if is_infinit(x0):
        x0 = 0
    if is_infinit(x1):
        x1 = 0

    if is_infinit(y0):
        y0 = 0
    if is_infinit(y1):
        y1 = 0

    logging.debug("{}".format([x0, y0, x1, y1]))

    kx, ky = make_ks(quantization_factor, x0, x1, y0, y1)
    if not quantization_factor:
        quantization_factor = x1 + 1
        x0 = y0 = 0

    class FindEmax(types):
        def __init__(self, obj):
            self.emax = 0
            self.obj = obj

        def point(self, point):
            x1 = point[0]
            y1 = point[1]
            x = ((x1 - x0) * kx)
            y = ((y1 - y0) * ky)
            ee = system['distance'](x1, y1, x / kx + x0, y / ky + y0)
            if ee > self.emax:
                self.emax = ee
            point[0] = int(x)
            point[1] = int(y)

    finde = FindEmax(objects)
    e_max = finde.emax
    clock(objects, system.ring_area)

    class findCoincidences(types):
        def line(self, line):
            for point in line:
                lines = ln.arcs.coincidenceLines(point)
                if not line in lines:
                    lines.append(line)

    fcInst = findCoincidences(objects)
    polygon = lambda poly: map(ln.lineClosed, poly)

    #Convert features to geometries, and stitch together arcs.
    class makeTopo(types):
        def Feature(self, feature):
            geometry = feature["geometry"]
            if feature['geometry'] == None:
                geometry = {}
            if feature.has_key('id'):
                geometry['id'] = feature['id']
            if feature.has_key('properties'):
                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(polygon, multiPolygon['coordinates'])

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

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

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

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

    makeTopoInst = makeTopo(objects)
    return {
        'type': "Topology",
        'transform': {
            'scale': [1.0 / kx, 1.0 / ky],
            'translate': [x0, y0]
        },
        'objects': makeTopoInst.outObj,
        'arcs': ln.getArcs()
    }