Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geospatial #110

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d632a80
added geospatial samples
sfc-gh-obielov Oct 20, 2022
55e861c
removed redundant files
sfc-gh-obielov Oct 20, 2022
d894027
nit
sfc-gh-obielov Oct 20, 2022
174551a
added st_intersection for geometry
sfc-gh-obielov Nov 4, 2022
22dc152
added makevalid function
sfc-gh-obielov Nov 7, 2022
4f20754
Update ST_TRANSFORM.sql
sfc-gh-obielov Nov 7, 2022
2416e93
updated makevalid
sfc-gh-obielov Nov 10, 2022
8a06501
nit
sfc-gh-obielov Nov 10, 2022
24dd137
added code for aggregated function for st_makeline
sfc-gh-obielov Nov 21, 2022
5ab55b5
updated the code
sfc-gh-obielov Nov 21, 2022
7622197
nit
sfc-gh-obielov Nov 21, 2022
61c281a
Merge branch 'main' into geospatial
sfc-gh-obielov Nov 22, 2022
4b16d66
renamed functions
sfc-gh-obielov Nov 22, 2022
8bddb68
reshuffled columns
sfc-gh-obielov Dec 2, 2022
df0e310
added reader for Shapefiles
sfc-gh-obielov Mar 8, 2023
206e11b
Create PY_MAKE2D.sql
sfc-gh-obielov Mar 23, 2023
0708a16
added four more geo functions
sfc-gh-obielov Mar 23, 2023
b7f48d3
merge
sfc-gh-obielov Mar 23, 2023
e2e9453
nit
sfc-gh-obielov Mar 23, 2023
b1fd408
added code sample for dynamic file access
sfc-gh-obielov Mar 30, 2023
c380309
Update PY_LOAD_GEOFILES.sql
sfc-gh-obielov Mar 30, 2023
252e21f
Update PY_LOAD_GEOFILES.sql
sfc-gh-obielov Mar 31, 2023
399df78
added more functions
sfc-gh-obielov Apr 14, 2023
bf2f0bc
Create PY_CONVEXHULL.sql
sfc-gh-obielov Apr 19, 2023
0b5088c
Create JS_TILEENVELOPE.sql
sfc-gh-obielov Apr 19, 2023
0612414
add handling for Null case
sfc-gh-obielov Aug 4, 2023
03230ba
Merge branch 'geospatial'
sfc-gh-obielov Aug 4, 2023
4dfcefc
nit
sfc-gh-obielov Aug 4, 2023
68469f5
Create PY_LOAD_MULTIPLE_SHAPEFILES.sql
sfc-gh-obielov Aug 28, 2023
adbe867
Create fixing_invalid_shapes.sql
sfc-gh-obielov Sep 27, 2023
1f94433
Update fixing_invalid_shapes.sql
sfc-gh-obielov Sep 27, 2023
cb65de1
Update fixing_invalid_shapes.sql
sfc-gh-obielov Sep 27, 2023
2e4423a
Update fixing_invalid_shapes.sql
sfc-gh-obielov Sep 27, 2023
546d669
Update fixing_invalid_shapes.sql
sfc-gh-obielov Sep 27, 2023
b2f3a15
Update fixing_invalid_shapes.sql
sfc-gh-obielov Sep 27, 2023
01e88b2
Update PY_LOAD_GEOFILES.sql
sfc-gh-obielov Nov 23, 2023
e0c750d
Update PY_LOAD_GEOFILES.sql
sfc-gh-obielov Nov 23, 2023
cbe5496
Merge branch 'main' of https://github.com/Snowflake-Labs/sf-samples
sfc-gh-obielov Nov 23, 2023
461cc73
Merge branch 'main' into geospatial
sfc-gh-obielov Nov 23, 2023
ca10fab
added new function
sfc-gh-obielov Nov 28, 2023
fec7aba
Create JS_POLYGON_TO_LINESTRING.sql
sfc-gh-obielov Dec 4, 2023
61a1523
Update JS_POLYGON_TO_LINESTRING.sql
sfc-gh-obielov Dec 4, 2023
7b284c3
Create basic_h3.py
sfc-gh-obielov Dec 15, 2023
50a7233
H3 streamlit sample
sfc-gh-obielov Feb 22, 2024
5da205b
Update main.py
sfc-gh-obielov Feb 22, 2024
c611145
Update PY_LOAD_GEOFILES.sql
sfc-gh-obielov Mar 13, 2024
f094fd6
updated functions
sfc-gh-obielov Mar 13, 2024
8626332
Create PY_COLLECTION_TO_POLYGONS.sql
sfc-gh-obielov Apr 1, 2024
4d8647e
Update basic_h3.py
sfc-gh-obielov Apr 1, 2024
3e98b41
Update basic_h3.py
sfc-gh-obielov Apr 1, 2024
d1620e7
Update basic_h3.py
sfc-gh-obielov Apr 1, 2024
a2cbab2
Merge branch 'main' into geospatial
sfc-gh-obielov Apr 1, 2024
c83c620
remove redundant files
sfc-gh-obielov Apr 1, 2024
6a8faf5
Update PY_COLLECTION_TO_POLYGONS.sql
sfc-gh-obielov Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create JS_TILEENVELOPE.sql
  • Loading branch information
sfc-gh-obielov committed Apr 19, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 0b5088c5c10aa5b51291e88831aa7f2af6739a27
64 changes: 64 additions & 0 deletions samples/geospatial/Python UDFs/JS_TILEENVELOPE.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-- Returns the boundary polygon of a tile given its zoom level and its X and Y indices.

CREATE OR REPLACE FUNCTION JS_TILEENVELOPE(zoomLevel REAL, xTile REAL, yTile REAL)
RETURNS GEOGRAPHY
LANGUAGE JAVASCRIPT
AS $$
function tile2long(x, z) {
return (x / Math.pow(2, z) * 360 - 180);
}

function tile2lat(y, z) {
const n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
return (180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n))));
}

minLon = tile2long(XTILE, ZOOMLEVEL);
minLat = tile2lat(YTILE + 1, ZOOMLEVEL);
maxLon = tile2long(XTILE + 1, ZOOMLEVEL);
maxLat = tile2lat(YTILE, ZOOMLEVEL);

return {
type: "Polygon",
coordinates: [
[
[minLon, minLat],
[minLon, maxLat],
[maxLon, maxLat],
[maxLon, minLat],
[minLon, minLat]
]
]
};
$$;



SELECT sST_TILEENVELOPE(7, 6, 9);

-- Invered function, to convert longitude and latitude to their corresponding x and y tile coordinates, respectively, for the given zoom level.


CREATE OR REPLACE FUNCTION JS_LNGLAT2TILEID(longitude FLOAT, latitude FLOAT, zoomLevel REAL)
RETURNS OBJECT
LANGUAGE JAVASCRIPT
AS
$$
function long2tile(lon, z) {
return Math.floor((lon + 180) / 360 * Math.pow(2, z));
}

function lat2tile(lat, z) {
return Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, z));
}

const xTile = long2tile(LONGITUDE, ZOOMLEVEL);
const yTile = lat2tile(LATITUDE, ZOOMLEVEL);

return {
xTile: xTile,
yTile: yTile
};
$$;

SELECT JS_LATLNG2TILEID(-161.71875, 82.116821929, 7)