titan.common¶
General functions useful in most geospatial contexts.
convert_gcs_path(file_path)
¶
Parses a file path and converts from a google cloud storage path to a gdal-readable path if necessary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
the input file path to check and convert. |
required |
Returns:
Type | Description |
---|---|
str
|
The modified file path if it's a GCS path, the original string if not. |
Source code in titan/common.py
17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
creation_options_to_dict(creation_options)
¶
Translates creation options from gdal formats to rasterio format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
creation_options |
list
|
gdal driver creation options. |
required |
Returns:
Name | Type | Description |
---|---|---|
rio_co |
dict
|
creation options in rasterio's expected dictionary format. |
Source code in titan/common.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
crs_match(crs1, crs2)
¶
Determines whether two coordinate reference systems are the same.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
crs1 |
pyproj.CRS
|
the first CRS, from a rasterio dataset, a GeoDataFrame, or a string with projection parameters. |
required |
crs2 |
pyproj.CRS
|
the second CRS, from the same sources above. |
required |
Returns:
Name | Type | Description |
---|---|---|
matches |
bool
|
Boolean for whether the CRSs match. |
Source code in titan/common.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
dimensions_match(raster1, raster2, precision=DEFAULT_PRECISION)
¶
Determines whether two raster extents and pixel sizes match.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raster1 |
str
|
path to the first raster to compare. |
required |
raster2 |
str
|
path to the second raster to compare. |
required |
precision |
float
|
the number of decimal points to round the affine transform. handles minor projection differences. |
DEFAULT_PRECISION
|
Returns:
Name | Type | Description |
---|---|---|
matches |
bool
|
Boolean for whether the dimensions match. |
Source code in titan/common.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
dtype_size(dtype)
¶
Returns the number of bytes for a raster data type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype |
Union[str, int]
|
the data type to check. accepts rasterio str dtypes or gdal int dtypes. |
required |
Returns:
Name | Type | Description |
---|---|---|
size |
int
|
data type size in bytes. |
Source code in titan/common.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
get_overview_levels(width, height)
¶
Compute the overviews to visualize a dataset at any zoom level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width |
int
|
the raster width |
required |
height |
int
|
the raster height |
required |
Returns:
Name | Type | Description |
---|---|---|
overview_levels |
List[int]
|
the levels to specify with e.g. gdal's ds.BuildOverviews() |
Source code in titan/common.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
get_reprojected_pixel_size(input_raster, dst_crs)
¶
Compute the output pixel size for a raster in a new CRS
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_raster |
str
|
path to a raster file |
required |
dst_crs |
pyproj.CRS
|
output projection to estimate |
required |
Returns:
Type | Description |
---|---|
Tuple[float, float]
|
xres, yres: reprojected pixel size |
Source code in titan/common.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
is_raster(file_path)
¶
Verifies whether a file is a valid raster dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
the input file to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
is_raster |
bool
|
true/false for whether the file is a raster. |
Source code in titan/common.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
is_vector(file_path)
¶
Verifies whether a file is a valid vector dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
the input file to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
is_vector |
bool
|
true/false for whethe the file is a vector. |
Source code in titan/common.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
parse_crs_string(string)
¶
Parses a string to determine the CRS/spatial projection format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string |
str
|
a string with CRS/projection data. |
required |
Returns:
Name | Type | Description |
---|---|---|
crs_type |
str
|
Str in ["wkt", "proj4", "epsg", "string"]. |
Source code in titan/common.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
string_to_crs(string)
¶
Converts a crs/projection string to a pyproj-readable CRS object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string |
str
|
a crs/projection string. |
required |
Returns:
Name | Type | Description |
---|---|---|
crs |
pyproj.CRS
|
a rasterio.crs.CRS object |
Source code in titan/common.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|