def test_to_wkt_list_simple_polygon(self): """Tests the to_wkt_list function for a polygon with inner rings.""" from pykml.util import to_wkt_list # create a polygon poly = KML.Polygon( KML.extrude('1'), KML.altitudeMode('relativeToGround'), KML.outerBoundaryIs( KML.LinearRing( KML.coordinates('-122.366278,37.818844,30 ' '-122.365248,37.819267,30 ' '-122.365640,37.819861,30 ' '-122.366669,37.819429,30 ' '-122.366278,37.818844,30 '), ), ), ) poly_wkt_list = to_wkt_list(poly) self.assertEqual(len(poly_wkt_list), 1) self.assertEqual(poly_wkt_list[0], ('POLYGON ((-122.366278 37.818844 30, ' '-122.365248 37.819267 30, ' '-122.365640 37.819861 30, ' '-122.366669 37.819429 30, ' '-122.366278 37.818844 30))'))
def test_to_wkt_list_complex_polygon(self): """Tests the to_wkt_list function for a polygon with inner rings.""" from pykml.util import to_wkt_list # create a polygon poly = KML.Polygon( KML.extrude('1'), KML.altitudeMode('relativeToGround'), KML.outerBoundaryIs( KML.LinearRing( KML.coordinates( '-122.366278,37.818844,30 ' '-122.365248,37.819267,30 ' '-122.365640,37.819861,30 ' '-122.366669,37.819429,30 ' '-122.366278,37.818844,30 ' ), ), ), KML.innerBoundaryIs( KML.LinearRing( KML.coordinates( '-122.366212,37.818977,30 ' '-122.365424,37.819294,30 ' '-122.365704,37.819731,30 ' '-122.366212,37.818977,30 ' ), ), ), KML.innerBoundaryIs( KML.LinearRing( KML.coordinates( '-122.366212,37.818977,30 ' '-122.365704,37.819731,30 ' '-122.366488,37.819402,30 ' '-122.366212,37.818977,30 ' ), ), ), ) poly_wkt_list = to_wkt_list(poly) self.assertEqual(len(poly_wkt_list), 1) self.assertEqual( poly_wkt_list[0], ('POLYGON ((-122.366278 37.818844 30, ' '-122.365248 37.819267 30, ' '-122.365640 37.819861 30, ' '-122.366669 37.819429 30, ' '-122.366278 37.818844 30), ' '(-122.366212 37.818977 30, ' '-122.365424 37.819294 30, ' '-122.365704 37.819731 30, ' '-122.366212 37.818977 30), ' '(-122.366212 37.818977 30, ' '-122.365704 37.819731 30, ' '-122.366488 37.819402 30, ' '-122.366212 37.818977 30))') )
def handle_uploaded_kmlfile(filename, objectid): from pykml import parser from pykml.util import to_wkt_list # check if the file is too large if filename.size >= filename.DEFAULT_CHUNK_SIZE: raise IOError # parse the incoming file doc = parser.fromstring(filename.read()) # look for geometries wkt_list = [{'geom': wkt} for wkt in to_wkt_list(doc)] return (wkt_list)
def handle_uploaded_kmlfile(filename,objectid): from pykml import parser from pykml.util import to_wkt_list # check if the file is too large if filename.size >= filename.DEFAULT_CHUNK_SIZE: raise IOError # parse the incoming file doc = parser.fromstring(filename.read()) # look for geometries wkt_list = [{'geom':wkt} for wkt in to_wkt_list(doc)] return(wkt_list)