georasters


Namegeorasters JSON
Version 0.5.29 PyPI version JSON
download
home_pagehttp://github.com/ozak/georasters
SummaryTools for working with Geographical Information System Rasters
upload_time2024-03-19 20:44:49
maintainer
docs_urlNone
authorÖmer Özak
requires_python
licenseGPLv3
keywords gis geospatial geographic raster vector zonal statistics spatial analysis
VCS
bugtrack_url
requirements numpy pandas docopt GDAL Cython None None matplotlib coverage fiona geopandas pysal affine rasterstats
Travis-CI
coveralls test coverage
            .. PyPI download statistics are broken, but the new PyPI warehouse makes PyPI
.. download statistics available through Google BigQuery
.. (https://bigquery.cloud.google.com).
.. Query to list package downloads by version:
..
   SELECT
     file.project,
     file.version,
     COUNT(*) as total_downloads,
     SUM(CASE WHEN REGEXP_EXTRACT(details.python, r"^([^\.]+\.[^\.]+)") = "2.6" THEN 1 ELSE 0 END) as py26_downloads,
     SUM(CASE WHEN REGEXP_EXTRACT(details.python, r"^([^\.]+\.[^\.]+)") = "2.7" THEN 1 ELSE 0 END) as py27_downloads,
     SUM(CASE WHEN REGEXP_EXTRACT(details.python, r"^([^\.]+)\.[^\.]+") = "3" THEN 1 ELSE 0 END) as py3_downloads,
   FROM
     TABLE_DATE_RANGE(
       [the-psf:pypi.downloads],
       TIMESTAMP("19700101"),
       CURRENT_TIMESTAMP()
     )
   WHERE
     file.project = 'georasters'
   GROUP BY
     file.project, file.version
   ORDER BY
     file.version DESC

GeoRasters
===========

|PyPiVersion|_
|PyPiDownloads|_
|BuildStatus|_ 
|CoverageStatus|_

The ``GeoRasters`` package is a python module that provides a fast and flexible
tool to work with GIS raster files. It provides the GeoRaster class, which makes working with rasters quite transparent and easy.
In a way it tries to do for rasters what GeoPandas does for geometries.

It includes tools to 

- Merge rasters
- Plot rasters
- Extract information from rasters
- Given a point (lat,lon) find its location in a raster
- Aggregate rasters to lower resolutions
- Align two rasters of different sizes to common area and size
- Get all the geographical information of raster
- Create GeoTiff files easily
- Load GeoTiff files as masked numpy rasters
- Clip raster using geometries
- Get zonal statistics using geometries
- Spatial analysis tools

Install
-------

.. code-block:: python
    
    pip install git+git://github.com/ozak/georasters.git
    pip install georasters
   
Example Usage: GeoRasters
-------------------------

.. code-block:: python
    
    import georasters as gr
    
    # Load data
    raster = './data/slope.tif'
    data = gr.from_file(raster)
    
    # Plot data
    data.plot()
    
    # Get some stats
    data.mean()
    data.sum()
    data.std()
    
    # Convert to Pandas DataFrame
    df = data.to_pandas()
    
    # Save transformed data to GeoTiff
    data2 = data**2
    data2.to_tiff('./data2')
    
    # Algebra with rasters
    data3 = np.sin(data.raster) / data2
    data3.plot()
    
    # Notice that by using the data.raster object, 
    # you can do any mathematical operation that handles 
    # Numpy Masked Arrays
    
    # Find value at point (x,y) or at vectors (X,Y)
    value = data.map_pixel(x,y)
    Value = data.map_pixel(X,Y)
    
Example Merge GeoRasters:
-------------------------

.. code-block:: python

    import os
    import georasters as gr
    import matplotlib.pyplot as plt

    DATA = "/path/to/tiff/files"

    # Import raster
    raster = os.path.join(DATA, 'pre1500.tif')
    data = gr.from_file(raster)
    (xmin, xsize, x, ymax, y, ysize) = data.geot

    # Split raster in two
    data1 = gr.GeoRaster(
        data.raster[:data.shape[0] / 2, :],
        data.geot,
        nodata_value=data.nodata_value,
        projection=data.projection,
        datatype=data.datatype,
    )
    data2 = gr.GeoRaster(
        data.raster[data.shape[0] / 2:, :],
        (xmin, xsize, x, ymax + ysize * data.shape[0] / 2, y, ysize),
        nodata_value=data.nodata_value,
        projection=data.projection,
        datatype=data.datatype,
    )

    # Plot both parts and save them
    plt.figure(figsize=(12, 8))
    data1.plot()
    plt.savefig(os.path.join(DATA, 'data1.png'), bbox_inches='tight')

.. image :: ./tests/data/data1.png
    
.. code-block:: python

    plt.figure(figsize=(12,8))
    data2.plot()
    plt.savefig(os.path.join(DATA,'data2.png'), bbox_inches='tight')
    
.. image :: ./tests/data/data2.png
    
.. code-block:: python

    # Generate merged raster
    
    data3 = data1.union(data2)
    
    # Plot it and save the figure
    
    plt.figure(figsize=(12,8))
    data3.plot()
    plt.savefig(os.path.join(DATA,'data3.png'), bbox_inches='tight')
    
.. image :: ./tests/data/data3.png
    

Another Merge:
--------------


Example Usage: Other functions
------------------------------

.. code-block:: python
    
    import georasters as gr
    
    # Get info on raster
    NDV, xsize, ysize, GeoT, Projection, DataType = gr.get_geo_info(raster)
    
    # Load raster
    data = load_tiff(raster)
       
    # Find location of point (x,y) on raster, e.g. to extract info at that location
    col, row = gr.map_pixel(x,y,GeoT[1],GeoT[-1], GeoT[0],GeoT[3])
    value = data[row,col]
    
    # Agregate raster by summing over cells in order to increase pixel size by e.g. 10
    gr.aggregate(data,NDV,(10,10))
    
    # Align two rasters
    data2 = load_tiff(raster2)
    (alignedraster_o, alignedraster_a, GeoT_a) = gr.align_rasters(raster, raster2, how=np.mean)
    
    # Create GeoRaster
    A=gr.GeoRaster(data, GeoT, nodata_value=NDV)

    # Load another raster
    NDV, xsize, ysize, GeoT, Projection, DataType = gr.get_geo_info(raster2)
    data = load_tiff(raster2)
    B=gr.GeoRaster(data2, GeoT, nodata_value=NDV)
    
    # Plot Raster
    A.plot()
    
    # Merge both rasters and plot
    C=B.merge(A)
    C.plot()
    
Issues
------

Find a bug? Report it via github issues by providing

- a link to download the smallest possible raster and vector dataset necessary to reproduce the error
- python code or command to reproduce the error
- information on your environment: versions of python, gdal and numpy and system memory

.. |BuildStatus| image:: https://api.travis-ci.org/ozak/georasters.png
.. _BuildStatus: https://travis-ci.org/ozak/georasters

.. |CoverageStatus| image:: https://img.shields.io/coveralls/ozak/georasters.svg
.. _CoverageStatus: https://coveralls.io/r/ozak/georasters

.. |PyPiVersion| image:: https://img.shields.io/pypi/v/georasters.svg
.. _PyPiVersion: :target: https://pypi.python.org/pypi/georasters/
    :alt: Version on Pypi

.. |PyPiDownloads| image:: https://img.shields.io/pypi/dm/georasters.svg
.. _PyPiDownloads:     :target: https://pypi.python.org/pypi/georasters/
     :alt: Pypi downloads

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/ozak/georasters",
    "name": "georasters",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "gis geospatial geographic raster vector zonal statistics spatial analysis",
    "author": "\u00d6mer \u00d6zak",
    "author_email": "omer@omerozak.com",
    "download_url": "https://files.pythonhosted.org/packages/f1/7a/a645b2fa63fe9af58e71e4d4959466062189510d08eb26236b49b62ad281/georasters-0.5.29.tar.gz",
    "platform": null,
    "description": ".. PyPI download statistics are broken, but the new PyPI warehouse makes PyPI\n.. download statistics available through Google BigQuery\n.. (https://bigquery.cloud.google.com).\n.. Query to list package downloads by version:\n..\n   SELECT\n     file.project,\n     file.version,\n     COUNT(*) as total_downloads,\n     SUM(CASE WHEN REGEXP_EXTRACT(details.python, r\"^([^\\.]+\\.[^\\.]+)\") = \"2.6\" THEN 1 ELSE 0 END) as py26_downloads,\n     SUM(CASE WHEN REGEXP_EXTRACT(details.python, r\"^([^\\.]+\\.[^\\.]+)\") = \"2.7\" THEN 1 ELSE 0 END) as py27_downloads,\n     SUM(CASE WHEN REGEXP_EXTRACT(details.python, r\"^([^\\.]+)\\.[^\\.]+\") = \"3\" THEN 1 ELSE 0 END) as py3_downloads,\n   FROM\n     TABLE_DATE_RANGE(\n       [the-psf:pypi.downloads],\n       TIMESTAMP(\"19700101\"),\n       CURRENT_TIMESTAMP()\n     )\n   WHERE\n     file.project = 'georasters'\n   GROUP BY\n     file.project, file.version\n   ORDER BY\n     file.version DESC\n\nGeoRasters\n===========\n\n|PyPiVersion|_\n|PyPiDownloads|_\n|BuildStatus|_ \n|CoverageStatus|_\n\nThe ``GeoRasters`` package is a python module that provides a fast and flexible\ntool to work with GIS raster files. It provides the GeoRaster class, which makes working with rasters quite transparent and easy.\nIn a way it tries to do for rasters what GeoPandas does for geometries.\n\nIt includes tools to \n\n- Merge rasters\n- Plot rasters\n- Extract information from rasters\n- Given a point (lat,lon) find its location in a raster\n- Aggregate rasters to lower resolutions\n- Align two rasters of different sizes to common area and size\n- Get all the geographical information of raster\n- Create GeoTiff files easily\n- Load GeoTiff files as masked numpy rasters\n- Clip raster using geometries\n- Get zonal statistics using geometries\n- Spatial analysis tools\n\nInstall\n-------\n\n.. code-block:: python\n    \n    pip install git+git://github.com/ozak/georasters.git\n    pip install georasters\n   \nExample Usage: GeoRasters\n-------------------------\n\n.. code-block:: python\n    \n    import georasters as gr\n    \n    # Load data\n    raster = './data/slope.tif'\n    data = gr.from_file(raster)\n    \n    # Plot data\n    data.plot()\n    \n    # Get some stats\n    data.mean()\n    data.sum()\n    data.std()\n    \n    # Convert to Pandas DataFrame\n    df = data.to_pandas()\n    \n    # Save transformed data to GeoTiff\n    data2 = data**2\n    data2.to_tiff('./data2')\n    \n    # Algebra with rasters\n    data3 = np.sin(data.raster) / data2\n    data3.plot()\n    \n    # Notice that by using the data.raster object, \n    # you can do any mathematical operation that handles \n    # Numpy Masked Arrays\n    \n    # Find value at point (x,y) or at vectors (X,Y)\n    value = data.map_pixel(x,y)\n    Value = data.map_pixel(X,Y)\n    \nExample Merge GeoRasters:\n-------------------------\n\n.. code-block:: python\n\n    import os\n    import georasters as gr\n    import matplotlib.pyplot as plt\n\n    DATA = \"/path/to/tiff/files\"\n\n    # Import raster\n    raster = os.path.join(DATA, 'pre1500.tif')\n    data = gr.from_file(raster)\n    (xmin, xsize, x, ymax, y, ysize) = data.geot\n\n    # Split raster in two\n    data1 = gr.GeoRaster(\n        data.raster[:data.shape[0] / 2, :],\n        data.geot,\n        nodata_value=data.nodata_value,\n        projection=data.projection,\n        datatype=data.datatype,\n    )\n    data2 = gr.GeoRaster(\n        data.raster[data.shape[0] / 2:, :],\n        (xmin, xsize, x, ymax + ysize * data.shape[0] / 2, y, ysize),\n        nodata_value=data.nodata_value,\n        projection=data.projection,\n        datatype=data.datatype,\n    )\n\n    # Plot both parts and save them\n    plt.figure(figsize=(12, 8))\n    data1.plot()\n    plt.savefig(os.path.join(DATA, 'data1.png'), bbox_inches='tight')\n\n.. image :: ./tests/data/data1.png\n    \n.. code-block:: python\n\n    plt.figure(figsize=(12,8))\n    data2.plot()\n    plt.savefig(os.path.join(DATA,'data2.png'), bbox_inches='tight')\n    \n.. image :: ./tests/data/data2.png\n    \n.. code-block:: python\n\n    # Generate merged raster\n    \n    data3 = data1.union(data2)\n    \n    # Plot it and save the figure\n    \n    plt.figure(figsize=(12,8))\n    data3.plot()\n    plt.savefig(os.path.join(DATA,'data3.png'), bbox_inches='tight')\n    \n.. image :: ./tests/data/data3.png\n    \n\nAnother Merge:\n--------------\n\n\nExample Usage: Other functions\n------------------------------\n\n.. code-block:: python\n    \n    import georasters as gr\n    \n    # Get info on raster\n    NDV, xsize, ysize, GeoT, Projection, DataType = gr.get_geo_info(raster)\n    \n    # Load raster\n    data = load_tiff(raster)\n       \n    # Find location of point (x,y) on raster, e.g. to extract info at that location\n    col, row = gr.map_pixel(x,y,GeoT[1],GeoT[-1], GeoT[0],GeoT[3])\n    value = data[row,col]\n    \n    # Agregate raster by summing over cells in order to increase pixel size by e.g. 10\n    gr.aggregate(data,NDV,(10,10))\n    \n    # Align two rasters\n    data2 = load_tiff(raster2)\n    (alignedraster_o, alignedraster_a, GeoT_a) = gr.align_rasters(raster, raster2, how=np.mean)\n    \n    # Create GeoRaster\n    A=gr.GeoRaster(data, GeoT, nodata_value=NDV)\n\n    # Load another raster\n    NDV, xsize, ysize, GeoT, Projection, DataType = gr.get_geo_info(raster2)\n    data = load_tiff(raster2)\n    B=gr.GeoRaster(data2, GeoT, nodata_value=NDV)\n    \n    # Plot Raster\n    A.plot()\n    \n    # Merge both rasters and plot\n    C=B.merge(A)\n    C.plot()\n    \nIssues\n------\n\nFind a bug? Report it via github issues by providing\n\n- a link to download the smallest possible raster and vector dataset necessary to reproduce the error\n- python code or command to reproduce the error\n- information on your environment: versions of python, gdal and numpy and system memory\n\n.. |BuildStatus| image:: https://api.travis-ci.org/ozak/georasters.png\n.. _BuildStatus: https://travis-ci.org/ozak/georasters\n\n.. |CoverageStatus| image:: https://img.shields.io/coveralls/ozak/georasters.svg\n.. _CoverageStatus: https://coveralls.io/r/ozak/georasters\n\n.. |PyPiVersion| image:: https://img.shields.io/pypi/v/georasters.svg\n.. _PyPiVersion: :target: https://pypi.python.org/pypi/georasters/\n    :alt: Version on Pypi\n\n.. |PyPiDownloads| image:: https://img.shields.io/pypi/dm/georasters.svg\n.. _PyPiDownloads:     :target: https://pypi.python.org/pypi/georasters/\n     :alt: Pypi downloads\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "Tools for working with Geographical Information System Rasters",
    "version": "0.5.29",
    "project_urls": {
        "Homepage": "http://github.com/ozak/georasters"
    },
    "split_keywords": [
        "gis",
        "geospatial",
        "geographic",
        "raster",
        "vector",
        "zonal",
        "statistics",
        "spatial",
        "analysis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "98bdfdae27c7462c3c4c1f39e358ac1e4cbaf6faaac61a5a13295d04f17123ef",
                "md5": "9fd3dbac665984347dc4553b1fca1698",
                "sha256": "0ee04949c3868fc37e42506e475932a034097978ab83358fd9f1e47e7c4890d0"
            },
            "downloads": -1,
            "filename": "georasters-0.5.29-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9fd3dbac665984347dc4553b1fca1698",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 30535,
            "upload_time": "2024-03-19T20:44:45",
            "upload_time_iso_8601": "2024-03-19T20:44:45.899804Z",
            "url": "https://files.pythonhosted.org/packages/98/bd/fdae27c7462c3c4c1f39e358ac1e4cbaf6faaac61a5a13295d04f17123ef/georasters-0.5.29-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f17aa645b2fa63fe9af58e71e4d4959466062189510d08eb26236b49b62ad281",
                "md5": "e14765abab5678a3b63162798865a741",
                "sha256": "b5b154fff5952d8374dbdee5c6dc73817efca41f2d3d9b4d72617dfbd86114d3"
            },
            "downloads": -1,
            "filename": "georasters-0.5.29.tar.gz",
            "has_sig": false,
            "md5_digest": "e14765abab5678a3b63162798865a741",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 2669775,
            "upload_time": "2024-03-19T20:44:49",
            "upload_time_iso_8601": "2024-03-19T20:44:49.189117Z",
            "url": "https://files.pythonhosted.org/packages/f1/7a/a645b2fa63fe9af58e71e4d4959466062189510d08eb26236b49b62ad281/georasters-0.5.29.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-19 20:44:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ozak",
    "github_project": "georasters",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "requirements": [
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "pandas",
            "specs": []
        },
        {
            "name": "docopt",
            "specs": []
        },
        {
            "name": "GDAL",
            "specs": []
        },
        {
            "name": "Cython",
            "specs": []
        },
        {
            "name": null,
            "specs": []
        },
        {
            "name": null,
            "specs": []
        },
        {
            "name": "matplotlib",
            "specs": []
        },
        {
            "name": "coverage",
            "specs": []
        },
        {
            "name": "fiona",
            "specs": []
        },
        {
            "name": "geopandas",
            "specs": []
        },
        {
            "name": "pysal",
            "specs": []
        },
        {
            "name": "affine",
            "specs": []
        },
        {
            "name": "rasterstats",
            "specs": []
        }
    ],
    "lcname": "georasters"
}
        
Elapsed time: 0.26147s