### Install Apache Sedona from source Source: https://github.com/apache/sedona/blob/master/docs/setup/install-python.md Install Apache Sedona by cloning the GitHub repository and running the setup script from the python directory. ```bash cd python python3 -m pip install . ``` -------------------------------- ### Install Sedona JARs in Notebook Source: https://github.com/apache/sedona/blob/master/docs/setup/fabric.md Use the %%configure magic command in a notebook to install the downloaded Sedona JARs. Replace the example URLs with your actual download links. ```python %%configure -f { "jars": ["https://repo1.maven.org/maven2/org/datasyslab/geotools-wrapper/1.5.1-28.2/geotools-wrapper-1.5.1-28.2.jar", "https://repo1.maven.org/maven2/org/apache/sedona/sedona-spark-shaded-3.4_2.12/1.5.1/sedona-spark-shaded-3.4_2.12-1.5.1.jar"] } ``` -------------------------------- ### ExpandAddress SQL Example Source: https://github.com/apache/sedona/blob/master/docs/api/sql/Address-Functions/ExpandAddress.md Demonstrates how to use the ExpandAddress function in SQL to get expanded forms of an address. Ensure libpostal data is accessible. ```sql SELECT ExpandAddress("100 W 1st St, Los Angeles, CA 90012"); ``` -------------------------------- ### Install Sedona Dependencies Source: https://github.com/apache/sedona/blob/master/docs/usecases/contrib/DownloadImageFromGEE.ipynb Install necessary Python libraries for Earth Engine and HDFS integration. Ensure these are installed before proceeding with the setup. ```python # NO TERMINAL # pip install earthengine-api # pip install geemap # pip install pywebhdfs ``` -------------------------------- ### Install uv Source: https://github.com/apache/sedona/blob/master/docs/setup/compile.md Install uv using the official installer script. This command fetches and executes the installation script for uv. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Install Dependencies with uv Source: https://github.com/apache/sedona/blob/master/docs/setup/compile.md Installs MkDocs and Material for MkDocs dependencies using uv. Ensure uv is installed first. ```bash python3 -m pip install uv uv sync --group docs ``` -------------------------------- ### Install Sphinx and Theme Source: https://github.com/apache/sedona/blob/master/python/sedona/README.md Installs Sphinx and the Read the Docs theme required for building the documentation. Ensure Python 3.6+ and pip are installed. ```bash pip install sphinx sphinx_rtd_theme ``` -------------------------------- ### Start Spark Cluster Source: https://github.com/apache/sedona/blob/master/docs/setup/cluster.md Execute this command in the root folder of your Apache Spark installation to start all Spark daemons. ```bash ./sbin/start-all.sh ``` -------------------------------- ### Install Apache Sedona Source: https://github.com/apache/sedona/blob/master/docs/blog/posts/intro-sedonadb.md Install SedonaDB with the necessary dependencies for database integration. This command installs the core library and the 'db' extra. ```bash pip install "apache-sedona[db]" ``` -------------------------------- ### Install Sedona with Kepler Extra Source: https://github.com/apache/sedona/blob/master/docs/tutorial/sql.md Install Sedona with the kepler-map extra to enable SedonaKepler functionality. ```bash pip install apache-sedona[kepler-map] ``` -------------------------------- ### Install Apache Sedona with Spark support Source: https://github.com/apache/sedona/blob/master/docs/setup/install-python.md Install Apache Sedona with the 'spark' extra to include pyspark as a dependency. ```bash pip install apache-sedona[spark] ``` -------------------------------- ### Install psycopg2-binary Source: https://github.com/apache/sedona/blob/master/docs/usecases/contrib/PostgresqlConnectionApacheSedona.ipynb Installs the psycopg2-binary package, which is a PostgreSQL adapter for Python. This is a prerequisite for direct database connections. ```bash ! pip install psycopg2-binary ``` -------------------------------- ### Install Sedona with PyDeck Extra Source: https://github.com/apache/sedona/blob/master/docs/tutorial/sql.md Install Sedona with the pydeck-map extra to enable SedonaPyDeck functionality. ```bash pip install apache-sedona[pydeck-map] ``` -------------------------------- ### ST_Expand SQL Example Source: https://github.com/apache/sedona/blob/master/docs/api/sql/Bounding-Box-Functions/ST_Expand.md An example demonstrating how to use the ST_Expand function in SQL to expand a POLYGON Z geometry. ```APIDOC ## ST_Expand SQL Example ### Description This example shows how to use the `ST_Expand` function with a `POLYGON Z` geometry and a uniform delta value. ### Method SQL ### Endpoint N/A (SQL Function) ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```sql SELECT ST_Expand( ST_GeomFromWKT('POLYGON Z((50 50 1, 50 80 2, 80 80 3, 80 50 2, 50 50 1))'), 10 ) ``` ### Response #### Success Response (200) Returns the expanded geometry. #### Response Example ``` POLYGON Z((40 40 -9, 40 90 -9, 90 90 13, 90 40 13, 40 40 -9)) ``` ``` -------------------------------- ### Physical Plan Example for RangeJoin Source: https://github.com/apache/sedona/blob/master/docs/api/sql/Optimizer.md An example of a physical plan for a spatial join query using RangeJoin, illustrating the execution strategy. ```text == Physical Plan == *(1) Project [id#14, id#25] +- RangeJoin rast#13: raster, geom#24: geometry, INTERSECTS, **org.apache.spark.sql.sedona_sql.expressions.RS_Intersects** :- LocalTableScan [rast#13, id#14] +- LocalTableScan [geom#24, id#25] ``` -------------------------------- ### Verify Sedona Installation with Python Source: https://github.com/apache/sedona/blob/master/docs/setup/fabric.md Run this Python code in your notebook to confirm that Sedona is installed correctly. It initializes Sedona and executes a spatial query. ```python from sedona.spark import * sedona = SedonaContext.create(spark) sedona.sql("SELECT ST_GeomFromEWKT('SRID=4269;POINT(40.7128 -74.0060)')").show() ``` -------------------------------- ### Set Up Python Development Environment with uv Source: https://github.com/apache/sedona/blob/master/docs/setup/compile.md Navigate to the Python directory, upgrade uv, and create a virtual environment using uv. ```bash cd python python -m pip install --upgrade uv uv venv --python 3.10 # or any supported version (>=3.8) ``` -------------------------------- ### ST_LineSubstring SQL Example Source: https://github.com/apache/sedona/blob/master/docs/api/snowflake/vector-data/Linear-Referencing/ST_LineSubstring.md This SQL example demonstrates how to use ST_LineSubstring to get a substring of a linestring. The start and end fractions determine the portion of the linestring to return. ```sql SELECT ST_LineSubstring(ST_GeomFromWKT('LINESTRING(25 50, 100 125, 150 190)'), 0.333, 0.666) as Substring ``` -------------------------------- ### Install Sedona Dependencies Source: https://github.com/apache/sedona/blob/master/docs/usecases/contrib/NdviSentinelApacheSedona.ipynb Install required Python packages for Sedona using pip. Ensure these are installed before proceeding with Sedona setup. ```python # pip install sklearn # pip install pyarrow # pip install fsspec ``` -------------------------------- ### Connect to SedonaDB Source: https://github.com/apache/sedona/blob/master/docs/blog/posts/intro-sedonadb-0-3.md Installs the SedonaDB library and establishes a connection to the database engine. Set 'interactive' to True for interactive mode. ```python # pip install "apache-sedona[db]" import sedona.db sd = sedona.db.connect() sd.options.interactive = True ``` -------------------------------- ### Install Sedona (Editable) and Run Python Tests Source: https://github.com/apache/sedona/blob/master/docs/setup/compile.md Install the Sedona Python package in editable mode and execute the test suite using pytest. ```bash cd python uv pip install -e . uv run pytest -v tests ``` -------------------------------- ### Set Up Spark and Environment Variables Source: https://github.com/apache/sedona/blob/master/docs/setup/compile.md Configure the SPARK_VERSION and download/extract Spark. Set SPARK_HOME and PYTHONPATH environment variables. ```bash export SPARK_VERSION=3.4.0 # or another supported version wget https://archive.apache.org/dist/spark/spark-${SPARK_VERSION}/spark-${SPARK_VERSION}-bin-hadoop3.tgz tar -xvzf spark-${SPARK_VERSION}-bin-hadoop3.tgz rm spark-${SPARK_VERSION}-bin-hadoop3.tgz export SPARK_HOME=$PWD/spark-${SPARK_VERSION}-bin-hadoop3 export PYTHONPATH=$SPARK_HOME/python ``` -------------------------------- ### Build and Serve Documentation Locally Source: https://github.com/apache/sedona/blob/master/docs/setup/compile.md Builds the documentation overrides and serves the website locally for testing. Requires Node.js and npm. ```bash cd docs-overrides && npm ci && npx gulp build cd .. uv run mike deploy --update-aliases latest-snapshot -b website -p uv run mike serve -b website ``` -------------------------------- ### ST_S2CellIDs Example Source: https://github.com/apache/sedona/blob/master/docs/api/flink/Spatial-Indexing/ST_S2CellIDs.md This example demonstrates how to use ST_S2CellIDs to get S2 Cell IDs for a LineString geometry at level 6. The output is an array of Long values representing the cell IDs. ```sql SELECT ST_S2CellIDs(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'), 6) ``` -------------------------------- ### Create a GeoSeries with a Polygon Source: https://github.com/apache/sedona/blob/master/docs/community/geopandas.md Example of creating a GeoSeries object with a Polygon geometry. This is a basic setup for geometry operations. ```python from sedona.spark.geopandas import GeoSeries from shapely.geometry import Polygon geoseries = GeoSeries([Polygon([(0, 0), (1, 0), (1, 1), (0, 0)])]) ``` -------------------------------- ### Connect to SedonaDB Source: https://github.com/apache/sedona/blob/master/docs/blog/posts/intro-sedonadb.md Instantiate a connection to SedonaDB. This is the first step after installation to begin interacting with the database. ```python import sedona.db sd = sedona.db.connect() ``` -------------------------------- ### Normalize Geometry using ST_Normalize Source: https://github.com/apache/sedona/blob/master/docs/api/flink/Geometry-Editors/ST_Normalize.md Use ST_Normalize to get the normalized form of a geometry. This example demonstrates normalizing a polygon. ```sql SELECT ST_AsEWKT(ST_Normalize(ST_GeomFromWKT('POLYGON((0 1, 1 1, 1 0, 0 0, 0 1))'))) ``` -------------------------------- ### Create Pointdf Table Source: https://github.com/apache/sedona/blob/master/docs/tutorial/snowflake/sql.md Creates a table named 'pointdf' with a single point geometry. This is a setup step for range join examples. ```sql CREATE OR REPLACE TABLE pointdf AS SELECT SEDONA.ST_GeomFromText('POINT(0.5 0.5)') pointshape; ``` -------------------------------- ### Run Spark Scala Shell with Sedona (Manual Download) Source: https://github.com/apache/sedona/blob/master/docs/setup/install-scala.md Use this command to start the Spark Scala shell after manually downloading the Sedona jars. Ensure the path points to your downloaded jar files. ```bash ./bin/spark-shell --jars /Path/To/SedonaJars.jar ``` -------------------------------- ### Create Polygondf Table Source: https://github.com/apache/sedona/blob/master/docs/tutorial/snowflake/sql.md Creates a table named 'polygondf' with a single polygon geometry. This is a setup step for range join examples. ```sql CREATE OR REPLACE TABLE polygondf AS SELECT SEDONA.ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))') polygonshape; ``` -------------------------------- ### Spark Physical Plan Example Source: https://github.com/apache/sedona/blob/master/docs/community/geopandas.md Illustrates the physical plan, detailing the actual execution strategy that Spark will use to run the query on the cluster. ```text == Physical Plan == Project [__index_level_0__#19L, **org.apache.spark.sql.sedona_sql.expressions.ST_Area** AS None#31] +- *(1) Scan ExistingRDD[__index_level_0__#19L,0#20] ``` -------------------------------- ### Convert Geometry to WKT String Source: https://github.com/apache/sedona/blob/master/docs/api/flink/Geometry-Output/ST_AsText.md Use ST_AsText to get the WKT representation of a geometry. This example shows converting a point with a specific SRID. ```sql SELECT ST_AsText(ST_SetSRID(ST_Point(1.0,1.0), 3021)) ``` -------------------------------- ### Initialize SedonaContext in Python Source: https://github.com/apache/sedona/blob/master/docs/setup/azure-synapse-analytics.md Configure and create a Sedona Spark session. Ensure the correct Spark JARs and Kryo registrator are specified for Sedona functionality. ```python from sedona.spark import SedonaContext config = ( SedonaContext.builder() .config( "spark.jars.packages", "org.apache.sedona:sedona-spark-shaded-3.4_2.12-1.6.1," "org.datasyslab:geotools-wrapper-1.6.1-28.2", ) .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer") .config( "spark.kryo.registrator", "org.apache.sedona.core.serde.SedonaKryoRegistrator" ) .config( "spark.sql.extensions", "org.apache.sedona.viz.sql.SedonaVizExtensions,org.apache.sedona.sql.SedonaSqlExtensions", ) .getOrCreate() ) sedona = SedonaContext.create(config) ``` -------------------------------- ### Use Spatial Partitioning (Alternative Python) Source: https://github.com/apache/sedona/blob/master/docs/tutorial/rdd.md This Python example demonstrates an alternative spatial partitioning strategy, partitioning the query window RDD first and then applying its partitioner to the object RDD. ```Python query_window_rdd.spatialPartitioning(GridType.KDBTREE) object_rdd.spatialPartitioning(query_window_rdd.getPartitioner()) ``` -------------------------------- ### Get the start point of a linestring Source: https://github.com/apache/sedona/blob/master/docs/api/flink/Geometry-Accessors/ST_StartPoint.md Use ST_StartPoint with ST_GeomFromText to retrieve the first point of a linestring. This function requires a Geometry object as input. ```sql SELECT ST_StartPoint(ST_GeomFromText('LINESTRING(100 150,50 60, 70 80, 160 170)')) ``` -------------------------------- ### SQL Example for RS_PixelAsPolygons Source: https://github.com/apache/sedona/blob/master/docs/api/sql/Pixel-Functions/RS_PixelAsPolygons.md Use this SQL query to get the text representation of polygons, pixel values, and coordinates for each pixel in the first band of a raster. ```sql SELECT ST_AsText(RS_PixelAsPolygons(raster, 1)) from rasters ``` -------------------------------- ### Get Dimension of Geometry with X,Y Coordinate Source: https://github.com/apache/sedona/blob/master/docs/api/flink/Geometry-Accessors/ST_NDims.md Use ST_NDims with ST_GeomFromText to determine the dimension of a point with only X and Y coordinates. This example shows a 2-dimensional point. ```sql SELECT ST_NDims(ST_GeomFromText('POINT(1 1)')) ``` -------------------------------- ### Initiate SedonaContext (Sedona >= 1.4.1) Source: https://github.com/apache/sedona/blob/master/docs/tutorial/viz.md Add this line after creating the Sedona config. If a SparkSession is already created, use SedonaContext.create(spark) instead. ```scala val sedona = SedonaContext.create(config) SedonaVizRegistrator.registerAll(sedona) ``` -------------------------------- ### Get Topological Dimension of GeometryCollection Source: https://github.com/apache/sedona/blob/master/docs/api/flink/Geometry-Accessors/ST_Dimension.md Use ST_Dimension to find the topological dimension of a GEOMETRYCOLLECTION. This example demonstrates its usage with a collection containing a LINESTRING and a POINT. ```sql SELECT ST_Dimension('GEOMETRYCOLLECTION(LINESTRING(1 1,0 0),POINT(0 0))'); ``` -------------------------------- ### Get Maximum Y Coordinate from Box2D Source: https://github.com/apache/sedona/blob/master/docs/api/sql/box2d/Box2D-Accessors/ST_YMax.md Use ST_YMax to retrieve the maximum Y coordinate from a Box2D. This example constructs a Box2D using ST_MakeBox2D and ST_Point, then applies ST_YMax to it. ```sql SELECT ST_YMax(ST_MakeBox2D(ST_Point(0.0, 0.0), ST_Point(10.0, 20.0))) ``` -------------------------------- ### Setting up Local Python Environment for Notebooks Source: https://github.com/apache/sedona/blob/master/docs/usecases/README.md Configure your local Python environment to match the Sedona Docker image's runtime dependencies for testing notebooks. ```bash export PYSPARK_SUBMIT_ARGS="--packages org.apache.sedona:sedona-spark-shaded-4.0_2.13:1.9.0,org.datasyslab:geotools-wrapper:1.9.0-33.5 --driver-memory 4g pyspark-shell" ``` -------------------------------- ### Get Dimension of Geometry with Z Coordinate Source: https://github.com/apache/sedona/blob/master/docs/api/flink/Geometry-Accessors/ST_NDims.md Use ST_NDims with ST_GeomFromEWKT to find the dimension of a point that includes a Z coordinate. This example demonstrates a 3-dimensional point. ```sql SELECT ST_NDims(ST_GeomFromEWKT('POINT(1 1 2)')) ``` -------------------------------- ### Install PySpark and Dependencies with uv Source: https://github.com/apache/sedona/blob/master/docs/setup/compile.md Add the correct PySpark version and other optional Spark dependencies using uv, then sync the environment. ```bash cd python # Use the correct PySpark version, otherwise latest version will be installed uv add pyspark==${SPARK_VERSION} --optional spark uv sync ``` -------------------------------- ### Create Polygon Table with SEDONA.ST_GeomFromText Source: https://github.com/apache/sedona/blob/master/docs/tutorial/snowflake/sql.md Creates a table named polygondf2 with a single polygon geometry using SEDONA.ST_GeomFromText. This is a setup step for spatial join examples. ```sql CREATE OR REPLACE TABLE polygondf2 AS SELECT SEDONA.ST_GeomFromText('POLYGON((0.5 0.5, 0.5 1, 1 1, 1 0.5, 0.5 0.5))') polygonshape; ``` -------------------------------- ### Makefile execution pipeline Source: https://github.com/apache/sedona/blob/master/docs/setup/compile.md Illustrates the workflow when executing 'make check'. The process involves uv syncing the environment and then prek executing the hooks. ```text [ Your CLI ] ──> [ make check ] ──> [ uv syncs environment ] ──> [ prek executes hooks ] ``` -------------------------------- ### Create Point Table with SEDONA.ST_GeomFromText Source: https://github.com/apache/sedona/blob/master/docs/tutorial/snowflake/sql.md Creates a table named pointdf2 with a single point geometry using SEDONA.ST_GeomFromText. This is a setup step for spatial join examples. ```sql CREATE OR REPLACE TABLE pointdf2 AS SELECT SEDONA.ST_GeomFromText('POINT(0 0)') pointshape; ``` -------------------------------- ### Compile Sedona with specific Spark and Scala versions Source: https://github.com/apache/sedona/blob/master/docs/community/develop.md Use the mvn clean install command with -Dspark and -Dscala arguments to compile Sedona against different versions of Spark and Scala. For example, to compile with Spark 3.4 and Scala 2.12, use: mvn clean install -Dspark=3.4 -Dscala=2.12. ```bash mvn clean install -DskipTests ``` ```bash mvn clean install -Dspark=3.4 -Dscala=2.12 ``` -------------------------------- ### Construct Geometry from WKB String with EWKT Output Source: https://github.com/apache/sedona/blob/master/docs/api/flink/Geometry-Constructors/ST_GeomFromWKB.md This example demonstrates constructing a Geometry from a WKB string and then converting it to EWKT format for verification. It supports EWKB format. ```sql SELECT ST_asEWKT(ST_GeomFromWKB('01010000a0e6100000000000000000f03f000000000000f03f000000000000f03f')) ``` -------------------------------- ### Add Measure to LineString - SQL Source: https://github.com/apache/sedona/blob/master/docs/api/flink/Linear-Referencing/ST_AddMeasure.md Use this SQL example to add measure values to a LineString geometry. The function interpolates M values between the provided start and end measures. ```sql SELECT ST_AsText(ST_AddMeasure( ST_GeomFromWKT('LINESTRING (0 0, 1 0, 2 0, 3 0, 4 0, 5 0)') )) ``` -------------------------------- ### Spark Logical Plan Example Source: https://github.com/apache/sedona/blob/master/docs/community/geopandas.md Displays the parsed logical plan of a Spark job, showing the initial transformations and operations before optimization. ```text == Parsed Logical Plan == Project [__index_level_0__#19L, 0#27 AS None#31] +- Project [ **org.apache.spark.sql.sedona_sql.expressions.ST_Area** AS 0#27, __index_level_0__#19L, __natural_order__#23L] +- Project [__index_level_0__#19L, 0#20, monotonically_increasing_id() AS __natural_order__#23L] +- LogicalRDD [__index_level_0__#19L, 0#20], false ``` -------------------------------- ### Calculate Raster Rotation with RS_Rotation Source: https://github.com/apache/sedona/blob/master/docs/api/sql/Raster-Accessors/RS_Rotation.md Use RS_Rotation to get the rotation angle of a raster. This example first creates an empty raster using RS_MakeEmptyRaster and then calculates its rotation. ```sql SELECT RS_Rotation( RS_MakeEmptyRaster(2, 10, 15, 1, 2, 1, -2, 1, 2, 0) ) ``` -------------------------------- ### Initialize SedonaContext and Read Parquet in Rust Source: https://github.com/apache/sedona/blob/master/docs/blog/posts/intro-sedonadb-0-2.md Example of initializing a local interactive SedonaContext in Rust, reading a Parquet file from a URL, sorting by name, and displaying the first 5 rows using show_sedona. Requires tokio runtime. ```rust use datafusion::{common::Result, prelude::*}; use sedona::context::{SedonaContext, SedonaDataFrame}; #[tokio::main] async fn main() -> Result<()> { let ctx = SedonaContext::new_local_interactive().await?; let url = "https://raw.githubusercontent.com/geoarrow/geoarrow-data/v0.2.0/natural-earth/files/natural-earth_cities_geo.parquet"; let df = ctx.read_parquet(url, Default::default()).await?; let output = df .sort_by(vec![col("name")])? .show_sedona(&ctx, Some(5), Default::default()) .await?; println!("{output}"); Ok(()) } ``` -------------------------------- ### Spark Analyzed Logical Plan Example Source: https://github.com/apache/sedona/blob/master/docs/community/geopandas.md Shows the analyzed logical plan after Spark has resolved all references and performed basic analysis. ```text == Analyzed Logical Plan == ... ``` -------------------------------- ### ST_PointN Function Usage Source: https://github.com/apache/sedona/blob/master/docs/api/sql/Geometry-Accessors/ST_PointN.md This snippet demonstrates how to use the ST_PointN function to get the Nth point from a linestring. It includes the function signature, SQL example, and expected result. ```APIDOC ## ST_PointN ### Description Return the Nth point in a single linestring or circular linestring in the geometry. Negative values are counted backwards from the end of the LineString, so that -1 is the last point. Returns NULL if there is no linestring in the geometry. ### Format `ST_PointN(geom: Geometry, n: Integer)` ### Return Type `Geometry` ### Since `v1.2.1` ### SQL Example ```sql SELECT ST_PointN(ST_GeomFromText("LINESTRING(0 0, 1 2, 2 4, 3 6)"), 2) ``` ### Result ``` POINT (1 2) ``` ``` -------------------------------- ### Create Folium Map with Markers Source: https://github.com/apache/sedona/blob/master/docs/usecases/contrib/VectorAnalysisApacheSedona.ipynb This Python snippet uses the Folium library to create an interactive map with markers for start and end points. It requires the Folium library to be installed. ```python # import folium start_point_arr = [-25.4695946, -54.5909028] end_point_arr = [-25.4786993, -54.57938] tooltip = "Click me!" # 3857 m = folium.Map( location=[-25.5172662, -54.6170038], zoom_start=12, tiles="OpenStreetMap", crs="EPSG3857", ) folium.Marker( start_point_arr, popup="Inicio", tooltip=tooltip, icon=folium.Icon(color="green"), ).add_to(m) folium.Marker( end_point_arr, popup="Fim", tooltip=tooltip, icon=folium.Icon(color="red") ).add_to(m) # lines = folium.vector_layers.PolyLine(locations=coordinates) # lines.add_to(m) # polygon = folium.vector_layers.Polygon(locations=coordinates_teste) # polygon.add_to(m) polygon_path = folium.vector_layers.Polygon(locations=short_path_coordinates) polygon_path.add_to(m) m ``` -------------------------------- ### Checkout KEYS Files with SVN Source: https://github.com/apache/sedona/blob/master/docs/community/release-manager.md Use SVN to check out the KEYS files from the Apache distribution repository. Ensure you use the --depth files option for efficiency. ```bash svn checkout https://dist.apache.org/repos/dist/dev/sedona/ sedona-dev --depth files ``` ```bash svn checkout https://dist.apache.org/repos/dist/release/sedona/ sedona-release --depth files ``` -------------------------------- ### Get Bounding Box GeoJSON Source: https://github.com/apache/sedona/blob/master/docs/usecases/contrib/VectorAnalysisApacheSedona.ipynb Calculates the bounding box of geometries for points closest to the start and end of a linestring, transforming it to GeoJSON format. Parses the GeoJSON to extract coordinates. ```python # FOLIUM EM 3857 dado em 4326 st_transform(st_union_aggr(geom),'epsg:3857','epsg:4326') json_lines = spark.sql( "select ST_AsGeoJSON(st_envelope_aggr(geom)) AS json from weight_index_tb where id in (" + str(closestostart) + "," + str(closestoend) + ")" ) json_lines_string_teste = json_lines.take(1)[0]["json"] coordinates_teste = json.loads(json_lines_string_teste)["coordinates"] ``` -------------------------------- ### Create and Inspect RDD Partitions Source: https://github.com/apache/sedona/blob/master/docs/usecases/contrib/NdviSentinelApacheSedona.ipynb Demonstrates creating a Resilient Distributed Dataset (RDD) from a local list and printing the number of partitions. This is useful for understanding data distribution in Spark. ```python rdd = spark.sparkContext.parallelize((0, 20)) print("From local[5]" + str(rdd.getNumPartitions())) ``` -------------------------------- ### Get Nth Point from LineString - SQL Source: https://github.com/apache/sedona/blob/master/docs/api/sql/Geometry-Accessors/ST_PointN.md Use this SQL example to extract the Nth point from a linestring. The index `n` can be positive or negative. Returns NULL if the geometry is not a linestring. ```sql SELECT ST_PointN(ST_GeomFromText("LINESTRING(0 0, 1 2, 2 4, 3 6)"), 2) ``` -------------------------------- ### ST_SRID Function Usage Source: https://github.com/apache/sedona/blob/master/docs/api/flink/Spatial-Reference-System/ST_SRID.md This snippet demonstrates how to use the ST_SRID function to get the SRID of a geometry. It shows the function signature, return type, and provides a practical SQL example. ```APIDOC ## ST_SRID ### Description Returns the spatial reference system identifier (SRID) of the geometry. ### Method SQL Function ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql SELECT ST_SRID(ST_SetSRID(ST_GeomFromWKT('POLYGON((1 1, 8 1, 8 8, 1 8, 1 1))'), 3021)) ``` ### Response #### Success Response (200) - **Return Type**: Integer - The SRID of the input geometry. #### Response Example ``` 3021 ``` ### Since v1.3.0 ``` -------------------------------- ### Connect to SedonaDB and Read Parquet Source: https://github.com/apache/sedona/blob/master/docs/blog/posts/intro-sedonadb-0-3.md Establishes a connection to SedonaDB, configures memory options, and reads a Parquet file into a view. Adjust memory limit and pool type as needed for your environment. ```python import sedona.db sd = sedona.db.connect() sd.options.memory_limit = "3g" sd.options.memory_pool_type = "fair" url = "https://github.com/geoarrow/geoarrow-data/releases/download/v0.2.0/microsoft-buildings_point.parquet" sd.read_parquet(url).to_view("buildings") ``` -------------------------------- ### Get Minimum X Coordinate of a Box3D Source: https://github.com/apache/sedona/blob/master/docs/api/sql/box3d/Box3D-Accessors/ST_XMin.md Use ST_XMin to retrieve the minimum X coordinate from a Box3D. This example constructs a Box3D using ST_3DMakeBox and ST_PointZ, then extracts its minimum X value. ```sql SELECT ST_XMin(ST_3DMakeBox(ST_PointZ(0.0, 0.0, -3.0), ST_PointZ(5.0, 10.0, 7.0))) ``` -------------------------------- ### Initialize Sedona Spark Context Source: https://github.com/apache/sedona/blob/master/docs/usecases/00-quickstart.ipynb Set up the Sedona Spark context by specifying the Spark master URL and creating a SparkSession. This is the entry point for using Sedona's spatial functionalities. ```python from sedona.spark import SedonaContext config = SedonaContext.builder().master("spark://localhost:7077").getOrCreate() sedona = SedonaContext.create(config) ``` -------------------------------- ### Configure Maven Settings for Authentication Source: https://github.com/apache/sedona/blob/master/docs/community/release-manager.md Set up your ~/.m2/settings.xml file to provide credentials for accessing GitHub and Apache repositories, and to configure GPG passphrase. ```xml github YOUR_GITHUB_USERNAME YOUR_GITHUB_TOKEN apache.snapshots.https YOUR_ASF_ID YOUR_ASF_PASSWORD apache.releases.https YOUR_ASF_ID YOUR_ASF_PASSWORD gpg YOUR_GPG_PASSPHRASE gpg ``` -------------------------------- ### Get Raster Y Coordinate Source: https://github.com/apache/sedona/blob/master/docs/api/sql/Raster-Accessors/RS_RasterToWorldCoordY.md Use RS_RasterToWorldCoordY to find the Y coordinate of a raster cell. Requires a raster object, column index, and row index. The example uses ST_MakeEmptyRaster to create a sample raster. ```sql SELECT RS_RasterToWorldCoordY(ST_MakeEmptyRaster(1, 5, 10, -123, 54, 5, -10, 0, 0, 4326), 1, 1) from rasters ``` -------------------------------- ### Get Nth Point from LineString using ST_PointN Source: https://github.com/apache/sedona/blob/master/docs/api/snowflake/vector-data/Geometry-Accessors/ST_PointN.md This SQL example demonstrates how to use ST_PointN to retrieve the second point from a LineString. The function takes the LineString geometry and the point index as input. ```sql SELECT ST_PointN(ST_GeomFromText('LINESTRING(0 0, 1 2, 2 4, 3 6)'), 2) AS geom ``` -------------------------------- ### Run Spark Scala Shell with Sedona (Local Mode, Manual Download) Source: https://github.com/apache/sedona/blob/master/docs/setup/install-scala.md Starts the Spark Scala shell in local mode with manually downloaded Sedona and geotools-wrapper jars. Provide the correct paths to your jar files. ```bash ./bin/spark-shell --jars /path/to/sedona-spark-shaded-3.3_2.12-{{ sedona.current_version }}.jar,/path/to/geotools-wrapper-{{ sedona.current_geotools }}.jar ``` -------------------------------- ### ST_3DMakeBox SQL Example Source: https://github.com/apache/sedona/blob/master/docs/api/sql/box3d/Box3D-Constructors/ST_3DMakeBox.md Constructs a Box3D from two ST_PointZ geometries and returns its Well-Known Text representation. Ensure inputs are valid POINT Z geometries to avoid exceptions. ```sql SELECT ST_AsText(ST_3DMakeBox(ST_PointZ(1.0, 2.0, 3.0), ST_PointZ(4.0, 5.0, 6.0))) ``` ```text BOX3D(1.0 2.0 3.0, 4.0 5.0 6.0) ```