コード例 #1
0
 def __init__(self,
              path,
              zoom,
              tile_size=256,
              bands=None,
              xy_tile_path="%s/%s.png"):
     self.gm = globalmaptiles.GlobalMercator(tileSize=256)
     self.resolution = self.gm.Resolution(zoom)
     self.zoom = zoom
     self.bands = range(1, 4) if bands is None else bands
     self.tile_size = tile_size
     xsize = 2**zoom * tile_size
     ysize = xsize
     max_lat = 20037508.342789244  # 1/2 the curcumference of the earther in meters
     min_lon = -20037508.342789244
     geo_transform = (min_lon, self.resolution, 0., max_lat, 0.,
                      -self.resolution)
     proj = projection_from_epsg(3785)  # Sphereical Mercator
     grid_size = (2 * max_lat / self.resolution,
                  2 * max_lat / self.resolution)
     tile_structure = "%d/" % zoom + xy_tile_path
     super(TiledWebRaster, self).__init__(path,
                                          xsize,
                                          ysize,
                                          geo_transform,
                                          proj,
                                          grid_size=grid_size,
                                          tile_structure=tile_structure)
コード例 #2
0
def to_feature(shp, _id):
    if isinstance(shp, BaseGeometry):
        return {
            "type": "Feature",
            "id": _id,
            "geometry": shp.__geo_interface__
        }

    elif isinstance(shp, Geometry):
        geom = shp.Clone()
        geom.TransformTo(projection_from_epsg())
        return {
            "type": "Feature",
            "id": _id,
            "geometry": json.loads(geom.ExportToJson())
        }
    elif pd.isnull(shp):
        return {
            "type": "Feature",
            "id": _id,
            "geometry": {
                "type": "Point",
                "coordinates": []
            }
        }
    else:
        raise ValueError("Unable create feature dict from shp")
コード例 #3
0
ファイル: vector.py プロジェクト: jamesdrussell/pyspatial
    def __init__(self, *args, **kwargs):

        proj = kwargs.pop("proj", None)

        if proj is None:
            proj = ut.projection_from_epsg()

        if isinstance(args[0], pd.Series):
            kwargs.pop("index", None)

        super(VectorLayer, self).__init__(*args, **kwargs)

        self.proj = proj
        self._sindex = None
コード例 #4
0
    def __init__(self, *args, **kwargs):

        proj = kwargs.pop("proj", None)

        if proj is None:
            proj = ut.projection_from_epsg()

        if isinstance(args[0], pd.Series):
            kwargs.pop("index", None)

        super(VectorLayer, self).__init__(*args, **kwargs)

        self.proj = proj
        self._sindex = None
コード例 #5
0
ファイル: vector.py プロジェクト: jamesdrussell/pyspatial
def read_geojson(path_or_str, index=None):
    """Create a vector layer from a geojson object.  Assumes that
    the data has a projection of EPSG:4326

    Parameters
    ----------
    path_or_str: string
        path or json string

    index: string or iterable
        If string, the column in the "properties" of each feature to use
        as the index. If iterable, use the iterable as the index.


    Returns
    -------

    Tuple of (VectorLayer, pandas.DataFrame of properties)"""

    if "FeatureCollection" not in path_or_str:
        geojson_str = fetch_geojson(path_or_str)
    else:
        geojson_str = path_or_str

    feats = pd.io.json.loads(geojson_str)["features"]

    if index is None:
        try:
            ids = map(lambda x: x["id"], feats)
        except KeyError:
            ids = range(len(feats))

        name = "index"
    elif isinstance(index, str) or isinstance(index, unicode):
        ids = map(lambda x: x["properties"][index], feats)
        name = index
    else:
        raise ValueError("Unable to create index.")

    proj = ut.projection_from_epsg()
    props = pd.DataFrame(map(lambda x: x["properties"], feats), index=ids)
    geoms = pd.Series(map(lambda x: shape(x["geometry"]), feats), index=ids) \
              .map(lambda x: to_geometry(x, proj=proj))

    props.index.name = name
    geoms.index.name = name

    return VectorLayer(geoms, proj=proj, index=ids), props
コード例 #6
0
def read_geojson(path_or_str, index=None):
    """Create a vector layer from a geojson object.  Assumes that
    the data has a projection of EPSG:4326

    Parameters
    ----------
    path_or_str: string
        path or json string

    index: string or iterable
        If string, the column in the "properties" of each feature to use
        as the index. If iterable, use the iterable as the index.


    Returns
    -------

    Tuple of (VectorLayer, pandas.DataFrame of properties)"""

    if "FeatureCollection" not in path_or_str:
        geojson_str = fetch_geojson(path_or_str)
    else:
        geojson_str = path_or_str

    feats = pd.io.json.loads(geojson_str)["features"]

    if index is None:
        try:
            ids = map(lambda x: x["id"], feats)
        except KeyError:
            ids = range(len(feats))

        name = "index"
    elif isinstance(index, str) or isinstance(index, unicode):
        ids = map(lambda x: x["properties"][index], feats)
        name = index
    else:
        raise ValueError("Unable to create index.")

    proj = ut.projection_from_epsg()
    props = pd.DataFrame(map(lambda x: x["properties"], feats), index=ids)
    geoms = pd.Series(map(lambda x: shape(x["geometry"]), feats), index=ids) \
              .map(lambda x: to_geometry(x, proj=proj))

    props.index.name = name
    geoms.index.name = name

    return VectorLayer(geoms, proj=proj, index=ids), props
コード例 #7
0
ファイル: visualize.py プロジェクト: aman-thakral/pyspatial
def to_feature(shp, _id):
    if isinstance(shp, BaseGeometry):
        return {"type": "Feature", "id": _id,
                "geometry": shp.__geo_interface__}

    elif isinstance(shp, Geometry):
        geom = shp.Clone()
        geom.TransformTo(projection_from_epsg())
        return {"type": "Feature", "id": _id,
                "geometry": json.loads(geom.ExportToJson())}
    elif pd.isnull(shp):
        return {"type": "Feature", "id": _id,
                "geometry": {"type": "Point",
                             "coordinates": []}}
    else:
        raise ValueError("Unable create feature dict from shp")
コード例 #8
0
ファイル: raster.py プロジェクト: aman-thakral/pyspatial
 def __init__(self, path, zoom, tile_size=256, bands=None,
              xy_tile_path="%s/%s.png"):
     self.gm = globalmaptiles.GlobalMercator(tileSize=256)
     self.resolution = self.gm.Resolution(zoom)
     self.zoom = zoom
     self.bands = range(1, 4) if bands is None else bands
     self.tile_size = tile_size
     xsize = 2**zoom*tile_size
     ysize = xsize
     max_lat = 20037508.342789244  # 1/2 the curcumference of the earther in meters
     min_lon = -20037508.342789244
     geo_transform = (min_lon, self.resolution, 0., max_lat, 0., -self.resolution)
     proj = projection_from_epsg(3785)  # Sphereical Mercator
     grid_size = (2*max_lat/self.resolution, 2*max_lat/self.resolution)
     tile_structure = "%d/" % zoom + xy_tile_path
     super(TiledWebRaster, self).__init__(path, xsize, ysize, geo_transform, proj,
                                          grid_size=grid_size, tile_structure=tile_structure)
コード例 #9
0
ファイル: test_vector.py プロジェクト: frallain/pyspatial
    def setup_class(cls):
        path1 = get_path("clu/four_shapes_2il_2ca.geojson")
        path2 = get_path("gz_2010_us_040_00_500k.json")
        path3 = get_path("bay_area_counties.geojson")
        path4 = get_path("bay_area_zips.geojson")

        cls.vl1, cls.df1 = vt.read_geojson(path1)
        cls.vl2, cls.df2 = vt.read_geojson(path2)
        cls.counties, cls.df3 = vt.read_geojson(path3, index="NAME")
        cls.sf = "San Francisco"
        proj = projection_from_epsg()
        rect.AssignSpatialReference(proj)
        farallon.AssignSpatialReference(proj)
        cls.counties[cls.sf] = cls.counties[cls.sf].Difference(farallon)
        cls.zips, cls.df4 = vt.read_geojson(path4, index="ZCTA5CE10")
        p = get_path("clu/four_shapes_2il_2ca.p")
        cls.df = pickle.load(open(p))
        assert isinstance(cls.counties, vt.VectorLayer)
        assert isinstance(cls.counties["San Francisco"], ogr.Geometry)
コード例 #10
0
ファイル: test_vector.py プロジェクト: granularag/pyspatial
    def setup_class(cls):
        path1 = get_path("clu/four_shapes_2il_2ca.geojson")
        path2 = get_path("gz_2010_us_040_00_500k.json")
        path3 = get_path("bay_area_counties.geojson")
        path4 = get_path("bay_area_zips.geojson")

        cls.vl1, cls.df1 = vt.read_geojson(path1)
        cls.vl2, cls.df2 = vt.read_geojson(path2)
        cls.counties, cls.df3 = vt.read_geojson(path3, index="NAME")
        cls.sf = "San Francisco"
        proj = projection_from_epsg()
        rect.AssignSpatialReference(proj)
        farallon.AssignSpatialReference(proj)
        cls.counties[cls.sf] = cls.counties[cls.sf].Difference(farallon)
        cls.zips, cls.df4 = vt.read_geojson(path4, index="ZCTA5CE10")
        p = get_path("clu/four_shapes_2il_2ca.p")
        cls.df = pickle.load(open(p))
        assert isinstance(cls.counties, vt.VectorLayer)
        assert isinstance(cls.counties["San Francisco"], ogr.Geometry)
コード例 #11
0
ファイル: vector.py プロジェクト: jamesdrussell/pyspatial
 def to_wgs84(self):
     """Transform the VectorLayer into WGS84"""
     proj = ut.projection_from_epsg()
     return self.transform(proj)
コード例 #12
0
 def to_wgs84(self, method="nneighbour"):
     return self.transform(projection_from_epsg(4326), method=method)
コード例 #13
0
 def to_wgs84(self):
     """Transform the VectorLayer into WGS84"""
     proj = ut.projection_from_epsg()
     return self.transform(proj)
コード例 #14
0
ファイル: raster.py プロジェクト: aman-thakral/pyspatial
 def to_wgs84(self, method="nneighbour"):
     return self.transform(projection_from_epsg(4326), method=method)