Пример #1
0
 def test_loading_broken(self):
     with TempFile() as fname:
         with open(fname, 'wb') as f:
             f.write(b"POLYGON((")
         polygon = load_polygons(fname)
         assert polygon.is_valid
         bbox, polygon = build_multipolygon(polygon, simplify=True)
Пример #2
0
 def test_loading_skip_non_polygon(self):
     with TempFile() as fname:
         with open(fname, 'w') as f:
             f.write("POINT(0 0)\n")
             f.write(VALID_POLYGON1)
         bbox, polygon = load_polygons(fname)
         eq_(polygon.type, 'Polygon')
Пример #3
0
 def test_loading_polygon(self):
     with TempFile() as fname:
         with open(fname, 'w') as f:
             f.write(VALID_POLYGON1)
         polygon = load_polygons(fname)
         bbox, polygon = build_multipolygon(polygon, simplify=True)
         eq_(polygon.type, 'Polygon')
Пример #4
0
def load_coverage(conf):
    if 'ogr_datasource' in conf:
        require_geom_support()
        srs = conf['ogr_srs']
        datasource = conf['ogr_datasource']
        if not re.match(r'^\w{2,}:', datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource)
        where = conf.get('ogr_where', None)
        geom = load_datasource(datasource, where)
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'polygons' in conf:
        require_geom_support()
        srs = conf['polygons_srs']
        geom = load_polygons(abspath(conf['polygons']))
        bbox, geom = build_multipolygon(geom, simplify=True)
    else:
        srs = conf['bbox_srs']
        bbox = conf['bbox']
        if isinstance(bbox, basestring):
            bbox = map(float, bbox.split(','))
        geom = None

    return coverage(geom or bbox, SRS(srs))
Пример #5
0
 def test_loading_polygon(self):
     with TempFile() as fname:
         with open(fname, 'w') as f:
             f.write(VALID_POLYGON1)
         polygon = load_polygons(fname)
         bbox, polygon = build_multipolygon(polygon, simplify=True)
         eq_(polygon.type, 'Polygon')
Пример #6
0
 def test_loading_broken(self):
     with TempFile() as fname:
         with open(fname, 'wb') as f:
             f.write(b"POLYGON((")
         polygon = load_polygons(fname)
         assert polygon.is_valid
         bbox, polygon = build_multipolygon(polygon, simplify=True)
Пример #7
0
def load_coverage(conf):
    if "ogr_datasource" in conf:
        require_geom_support()
        srs = conf["ogr_srs"]
        datasource = conf["ogr_datasource"]
        if not re.match(r"^\w{2,}:", datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource)
        where = conf.get("ogr_where", None)
        geom = load_datasource(datasource, where)
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif "polygons" in conf:
        require_geom_support()
        srs = conf["polygons_srs"]
        geom = load_polygons(abspath(conf["polygons"]))
        bbox, geom = build_multipolygon(geom, simplify=True)
    else:
        srs = conf["bbox_srs"]
        bbox = conf["bbox"]
        if isinstance(bbox, basestring):
            bbox = map(float, bbox.split(","))
        geom = None

    return coverage(geom or bbox, SRS(srs))
Пример #8
0
 def test_loading_multipolygon(self):
     with TempFile() as fname:
         with open(fname, 'w') as f:
             f.write(VALID_POLYGON1)
             f.write('\n')
             f.write(VALID_POLYGON2)
         bbox, polygon = load_polygons(fname)
         eq_(polygon.type, 'MultiPolygon')
Пример #9
0
 def test_loading_polygon(self):
     with TempFile() as fname:
         with open(fname, "w") as f:
             f.write(VALID_POLYGON1)
         polygon = load_polygons(fname)
         bbox, polygon = build_multipolygon(polygon, simplify=True)
         assert polygon.is_valid
         eq_(polygon.type, "Polygon")
Пример #10
0
 def test_loading_skip_non_polygon(self):
     with TempFile() as fname:
         with open(fname, 'wb') as f:
             f.write(b"POINT(0 0)\n")
             f.write(VALID_POLYGON1)
         polygon = load_polygons(fname)
         bbox, polygon = build_multipolygon(polygon, simplify=True)
         assert polygon.is_valid
         eq_(polygon.type, 'Polygon')
Пример #11
0
 def test_loading_skip_non_polygon(self):
     with TempFile() as fname:
         with open(fname, 'wb') as f:
             f.write(b"POINT(0 0)\n")
             f.write(VALID_POLYGON1)
         polygon = load_polygons(fname)
         bbox, polygon = build_multipolygon(polygon, simplify=True)
         assert polygon.is_valid
         eq_(polygon.type, 'Polygon')
Пример #12
0
 def test_loading_multipolygon(self):
     with TempFile() as fname:
         with open(fname, 'wb') as f:
             f.write(VALID_POLYGON1)
             f.write(b'\n')
             f.write(VALID_POLYGON2)
         polygon = load_polygons(fname)
         bbox, polygon = build_multipolygon(polygon, simplify=True)
         assert polygon.is_valid
         eq_(polygon.type, 'MultiPolygon')
Пример #13
0
 def test_loading_intersecting_polygons(self):
     # check that the self intersection is eliminated
     # otherwise the geometry will be invalid
     with TempFile() as fname:
         with open(fname, 'w') as f:
             f.write(INTERSECTING_POLYGONS)
         polygon = load_polygons(fname)
         bbox, polygon = build_multipolygon(polygon, simplify=True)
         assert polygon.is_valid
         eq_(polygon.type, 'Polygon')
         assert polygon.equals(shapely.geometry.Polygon([(0, 0), (15, 0), (15, 10), (0, 10)]))
Пример #14
0
 def test_loading_intersecting_polygons(self):
     # check that the self intersection is eliminated
     # otherwise the geometry will be invalid
     with TempFile() as fname:
         with open(fname, 'w') as f:
             f.write(INTERSECTING_POLYGONS)
         polygon = load_polygons(fname)
         bbox, polygon = build_multipolygon(polygon, simplify=True)
         assert polygon.is_valid
         assert polygon.type == 'Polygon'
         assert polygon.equals(shapely.geometry.Polygon([(0, 0), (15, 0), (15, 10), (0, 10)]))
Пример #15
0
def load_coverage(conf, base_path=None):
    if 'ogr_datasource' in conf:
        require_geom_support()
        srs = conf['ogr_srs']
        datasource = conf['ogr_datasource']
        if not re.match(r'^\w{2,}:', datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource, base_path=base_path)
        where = conf.get('ogr_where', None)
        geom = load_ogr_datasource(datasource, where)
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'polygons' in conf:
        require_geom_support()
        srs = conf['polygons_srs']
        geom = load_polygons(abspath(conf['polygons'], base_path=base_path))
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'bbox' in conf:
        srs = conf.get('bbox_srs') or conf['srs']
        bbox = conf['bbox']
        if isinstance(bbox, string_type):
            bbox = [float(x) for x in bbox.split(',')]
        geom = None
    elif 'datasource' in conf:
        require_geom_support()
        datasource = conf['datasource']
        srs = conf['srs']
        if isinstance(datasource, (list, tuple)):
            bbox = datasource
            geom = None
        elif bbox_string_re.match(datasource):
            bbox = [float(x) for x in datasource.split(',')]
            geom = None
        else:
            if not re.match(r'^\w{2,}:', datasource):
                # looks like a file and not PG:, MYSQL:, etc
                # make absolute path
                datasource = abspath(datasource, base_path=base_path)
            where = conf.get('where', None)
            geom = load_datasource(datasource, where)
            bbox, geom = build_multipolygon(geom, simplify=True)
    else:
        return None
    return coverage(geom or bbox, SRS(srs))
Пример #16
0
def load_coverage(conf):
    if 'ogr_datasource' in conf:
        require_geom_support()
        srs = conf['ogr_srs']
        datasource = conf['ogr_datasource']
        if not re.match(r'^\w{2,}:', datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource)
        where = conf.get('ogr_where', None)
        bbox, geom = load_datasource(datasource, where)
    elif 'polygons' in conf:
        require_geom_support()
        srs = conf['polygons_srs']
        bbox, geom = load_polygons(abspath(conf['polygons']))
    else:
        srs = conf['bbox_srs']
        bbox = conf['bbox']
        if isinstance(bbox, basestring):
            bbox = map(float, bbox.split(','))
        geom = None

    return coverage(geom or bbox, SRS(srs))
        
Пример #17
0
def load_coverage(conf, base_path=None):
    clip = False
    if 'clip' in conf:
        clip = conf['clip']

    if 'union' in conf:
        parts = []
        for cov in conf['union']:
            parts.append(load_coverage(cov))
        return union_coverage(parts, clip=clip)
    elif 'intersection' in conf:
        parts = []
        for cov in conf['intersection']:
            parts.append(load_coverage(cov))
        return intersection_coverage(parts, clip=clip)
    elif 'difference' in conf:
        parts = []
        for cov in conf['difference']:
            parts.append(load_coverage(cov))
        return diff_coverage(parts, clip=clip)
    elif 'ogr_datasource' in conf:
        require_geom_support()
        srs = conf['ogr_srs']
        datasource = conf['ogr_datasource']
        if not re.match(r'^\w{2,}:', datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource, base_path=base_path)
        where = conf.get('ogr_where', None)
        geom = load_ogr_datasource(datasource, where)
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'polygons' in conf:
        require_geom_support()
        srs = conf['polygons_srs']
        geom = load_polygons(abspath(conf['polygons'], base_path=base_path))
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'bbox' in conf:
        srs = conf.get('bbox_srs') or conf['srs']
        bbox = conf['bbox']
        if isinstance(bbox, string_type):
            bbox = [float(x) for x in bbox.split(',')]
        geom = None
    elif 'datasource' in conf:
        require_geom_support()
        datasource = conf['datasource']
        srs = conf['srs']
        if isinstance(datasource, (list, tuple)):
            bbox = datasource
            geom = None
        elif bbox_string_re.match(datasource):
            bbox = [float(x) for x in datasource.split(',')]
            geom = None
        else:
            if not re.match(r'^\w{2,}:', datasource):
                # looks like a file and not PG:, MYSQL:, etc
                # make absolute path
                datasource = abspath(datasource, base_path=base_path)
            where = conf.get('where', None)
            geom = load_datasource(datasource, where)
            bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'expire_tiles' in conf:
        require_geom_support()
        filename = abspath(conf['expire_tiles'])
        geom = load_expire_tiles(filename)
        _, geom = build_multipolygon(geom, simplify=False)
        return coverage(geom, SRS(3857))
    else:
        return None

    return coverage(geom or bbox, SRS(srs), clip=clip)
Пример #18
0
def load_coverage(conf, base_path=None):
    clip = False
    if 'clip' in conf:
        clip = conf['clip']

    if 'union' in conf:
        parts = []
        for cov in conf['union']:
            parts.append(load_coverage(cov))
        return union_coverage(parts, clip=clip)
    elif 'intersection' in conf:
        parts = []
        for cov in conf['intersection']:
            parts.append(load_coverage(cov))
        return intersection_coverage(parts, clip=clip)
    elif 'difference' in conf:
        parts = []
        for cov in conf['difference']:
            parts.append(load_coverage(cov))
        return diff_coverage(parts, clip=clip)
    elif 'ogr_datasource' in conf:
        require_geom_support()
        srs = conf['ogr_srs']
        datasource = conf['ogr_datasource']
        if not re.match(r'^\w{2,}:', datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource, base_path=base_path)
        where = conf.get('ogr_where', None)
        geom = load_ogr_datasource(datasource, where)
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'polygons' in conf:
        require_geom_support()
        srs = conf['polygons_srs']
        geom = load_polygons(abspath(conf['polygons'], base_path=base_path))
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'bbox' in conf:
        srs = conf.get('bbox_srs') or conf['srs']
        bbox = conf['bbox']
        if isinstance(bbox, string_type):
            bbox = [float(x) for x in bbox.split(',')]
        geom = None
    elif 'datasource' in conf:
        require_geom_support()
        datasource = conf['datasource']
        srs = conf['srs']
        if isinstance(datasource, (list, tuple)):
            bbox = datasource
            geom = None
        elif bbox_string_re.match(datasource):
            bbox = [float(x) for x in datasource.split(',')]
            geom = None
        else:
            if not re.match(r'^\w{2,}:', datasource):
                # looks like a file and not PG:, MYSQL:, etc
                # make absolute path
                datasource = abspath(datasource, base_path=base_path)
            where = conf.get('where', None)
            geom = load_datasource(datasource, where)
            bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'expire_tiles' in conf:
        require_geom_support()
        filename = abspath(conf['expire_tiles'])
        geom = load_expire_tiles(filename)
        _, geom = build_multipolygon(geom, simplify=False)
        return coverage(geom, SRS(3857))
    else:
        return None

    return coverage(geom or bbox, SRS(srs), clip=clip)
Пример #19
0
 def test_loading_broken(self):
     with TempFile() as fname:
         with open(fname, 'w') as f:
             f.write("POLYGON((")
         bbox, polygon = load_polygons(fname)
Пример #20
0
 def test_loading_broken(self):
     with TempFile() as fname:
         with open(fname, 'wb') as f:
             f.write(b"POLYGON((")
         with pytest.raises(ReadingError):
             load_polygons(fname)