Created
December 15, 2021 13:33
-
-
Save michaeldorman/0bfea5951bdb396fc72e32b965218994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
import geopandas as gpd | |
import rasterio | |
# numpy | |
a = np.array([3, 8, -2, 43, 12, 1, 8]) | |
b = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]) | |
c = np.arange(1, 25).reshape((2, 3, 4)) | |
m = np.array([[ np.nan, np.nan, np.nan, np.nan, np.nan, 3., 3.], | |
[ np.nan, np.nan, np.nan, np.nan, 4., 6., 4.], | |
[ np.nan, np.nan, np.nan, np.nan, 6., 9., 7.], | |
[ np.nan, 61., 9., 4., 9., 10., 16.], | |
[ np.nan, 106., 132., 11., 6., 6., 27.], | |
[ np.nan, 47., 254., 146., 6., 6., 12.], | |
[ np.nan, 31., 233., 340., 163., 13., 64.], | |
[ 3., 39., 253., 383., 448., 152., 39.], | |
[ 5., 32., 199., 357., 414., 360., 48.], | |
[ 7., 49., 179., 307., 403., 370., 55.]]) | |
# pandas | |
d = { | |
"name": pd.Series(["Beer-Sheva Center", "Beer-Sheva University", "Dimona"], name = "name"), | |
"lines": pd.Series(np.array([4, 5, 1])), | |
"city": pd.Series(["Beer-Sheva", "Beer-Sheva", "Dimona"]), | |
"piano": pd.Series([False, True, False]), | |
"lon": pd.Series([34.798443, 34.812831, 35.011635]), | |
"lat": pd.Series([31.243288, 31.260284, 31.068616]) | |
} | |
dat = pd.DataFrame(d) | |
dat | |
# geopandas | |
geom = gpd.points_from_xy(dat["lon"], dat["lat"]) | |
geom = gpd.GeoSeries(geom) | |
layer = gpd.GeoDataFrame(dat, geometry = geom, crs = 4326) | |
# rasterio | |
dem = m.copy() | |
dem[np.isnan(dem)] = -9999 | |
dem = dem.astype("int16") | |
transform = rasterio.transform.from_origin(662317, 3658412, 90, 90) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment