Welcome to eeconvert’s documentation!¶
Installation¶
Step 1:¶
One of the packages’ dependencies is pyproj which requires a compiler to be installed.
Linux
apt-get install gcc
MacOS
Using brew: brew install llvm
Windows
Install MicroSoft Visual
Step 2:¶
pip install eeconvert
eeconvert package¶
Module contents¶
-
eeconvert.
defaultMap
()¶
-
eeconvert.
dfToFc
(df)¶ converts a dataframe to a featurecollection without geometry
- Args:
- df (pandas.dataFrame) : the input dataframe
- Returns:
- fc (ee.FeatureCollection) : feature collection with empty geometry
-
eeconvert.
dfToPostgreSQL
(connection, df, tableName, saveIndex=True)¶ this function uploads a dataframe to table in AWS RDS.
- Args:
- connection (sqlalchemy.engine.base.Connection) :database connection df (pandas.GeoDataFrame) : input dataFrame tableName (string) : table name (string) saveIndex (boolean, optional) : save geoDataFrame index column in separate column in postgresql, otherwise discarded. Default is True
- Returns:
- gdf (geoPandas.GeoDataFrame) : the geodataframe loaded from the database. Should match the input dataframe
- todo:
- currently removes table if exists. Include option to break or append
-
eeconvert.
eeImageToFoliumLayer
(image, layerName='eeLayer', visParams=None, foliumKwargs={})¶ Function to add Google Earch Engine tile layer as a Folium layer. based on https://github.com/mccarthyryanc/folium_gee/blob/master/folium_gee.py hence PEP8 instead of camelcase
- Args:
- image (ee.Image) : Google Earth Engine Image. layerName (string) : Layer name for in folium layerControl. Default : “eeLayer” vis_params (dict) : Dict with visualization parameters as used in Google Earth Engine. Note that color palatte inputs in python needs to be structured like: “palette”: “ff0000,ff0000,0013ff” folium_kwargs (dict) : Keyword args for Folium Map.
- Returns:
- layer () : folium Layer. Add to map by applying method .add(m)
-
eeconvert.
fcToDf
(fc)¶ converts a featurecollection to a Pandas DataFrame. Use this function for featureCollections without geometries. For featureCollections with geometries, use fcToGdf()
- Args:
- fc (ee.FeatureCollection) : the earth engine feature collection to convert. Size is limited to memory (geopandas limitation) crs (dictionary, optional) : the coordinate reference system in geopandas format. Defaults to {‘init’ :’epsg:4326’}
- Returns:
- df (pandas.DataFrame) : the corresponding dataframe.
-
eeconvert.
fcToGdf
(fc, crs={'init': 'epsg:4326'})¶ converts a featurecollection to a geoPandas GeoDataFrame. Use this function only if all features have a geometry.
caveats: Currently only supports non-geodesic (planar) geometries because of limitations in geoPandas and Leaflet. Geodesic geometries are simply interpreted as planar geometries. FeatureCollections larger than memory are currently not supported. Consider splitting data and merging (server side) afterwards.
- Args:
- fc (ee.FeatureCollection) : the earth engine feature collection to convert. crs (dictionary, optional) : the coordinate reference system in geopandas format. Defaults to {‘init’ :’epsg:4326’}
- Returns:
- gdf (geoPandas.GeoDataFrame or pandas.DataFrame) : the corresponding (geo)dataframe.
-
eeconvert.
gdfToFc
(gdf)¶ converts a geodataframe to a featurecollection
- Args:
- gdf (geoPandas.GeoDataFrame) : the input geodataframe
- Returns:
- fc (ee.FeatureCollection) : feature collection (server side)
-
eeconvert.
gdfToFoliumGroup
(gdf, name='noName')¶ converts a geodataframe to a folium featureGroup with the properties as a popup child
- Args:
- gdf (geoPandas.GeoDataFrame) : the input geodataframe name (string) : output folium feature group name
- Returns:
- fc (ee.FeatureCollection) : feature collection (server side)
-
eeconvert.
gdfToPostGIS
(connection, gdf, tableName, saveIndex=True)¶ this function uploads a geodataframe to table in AWS RDS.
It handles combined polygon/multipolygon geometry and stores it in valid multipolygon in epsg 4326.
- Args:
- connection (sqlalchemy.engine.base.Connection) : postGIS enabled database connection gdf (geoPandas.GeoDataFrame) : input geoDataFrame tableName (string) : postGIS table name (string) saveIndex (boolean, optional) : save geoDataFrame index column in separate column in postgresql, otherwise discarded. Default is True
- Returns:
- gdf (geoPandas.GeoDataFrame) : the geodataframe loaded from the database. Should match the input dataframe
- todo:
- currently removes table if exists. Include option to break or append
-
eeconvert.
noGeometryEEFeature
(row)¶
-
eeconvert.
postGisToGdf
(connection, tableName)¶ this function gets a geoDataFrame from a postGIS database instance
- Args:
- connection (sqlalchemy.engine.base.Connection) : postGIS enabled database connection tableName (string) : table name
- Returns:
- gdf (geoPandas.GeoDataFrame) : the geodataframe from PostGIS
- todo:
- allow for SQL filtering
-
eeconvert.
postgreSQLToDf
(connection, tableName)¶ this function gets a dataFrame from a postGIS database instance
- Args:
- connection (sqlalchemy.engine.base.Connection) : postGIS enabled database connection tableName (string) : table name
- Returns:
- df (pandas.DataFrame) : the dataframe from PostGIS
- todo:
- allow for SQL filtering
-
eeconvert.
rdsConnect
(database_identifier, database_name, master_username)¶ open a connection to AWS RDS
in addition to specifying the arguments you need to store your password in a file called .password in the current working directory. You can do this using the command line or Jupyter. Make sure to have your .gitignore file up to date.
- Args:
database_identifier (string) : postgresql database identifier used when you set up the AWS RDS instance.
database_name (string) : the database name to connect to.
master_username (string) : the master username for the database.
- Returns:
engine (sqlalchemy.engine.base.Engine) : database engine.
connection (sqlalchemy.engine.base.Connection) : database connection.
-
eeconvert.
shapelyToEEFeature
(row)¶
-
eeconvert.
shapelyToFoliumFeature
(row)¶ converts a shapely feature to a folium (leaflet) feature. row needs to have a geometry column. CRS is 4326
- Args:
- row (geoPandas.GeoDataFrame row) : the input geodataframe row. Appy this function to a geodataframe gdf.appy(function, 1)
- Returns:
- foliumFeature (folium feature) : foliumFeature with popup child.
LICENCE¶
MIT License
Copyright (c) 2018 Rutger Hofste
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.