geom
¶
Functions:
-
applyBuffer–This function applies a buffer to any geom, avoiding edge issues with geoms
-
box–Make an ogr polygon object from extents.
-
convertGeoJson–Make a geometry from a well known text (WKT) string.
-
convertWKT–Make a geometry from a well known text (WKT) string.
-
divideMultipolygonIntoEasternAndWesternPart–Multipolygons spanning the antimeridian (this includes polygons that are
-
drawGeoms–Draw geometries onto a matplotlib figure.
-
empty–Make a generic OGR geometry of a desired type.
-
extractVerticies–Get all vertices found on the geometry as a Nx2 numpy.ndarray.
-
fixOutOfBoundsGeoms–This function allows to deal with polygons that protrude over the SRS bounds
-
flatten–Flatten a list of geometries into a single geometry object.
-
line–Creates an OGR Line object from a given set of points.
-
makeBox–Alias for geokit.geom.box(...).
-
makeEmpty–Alias for geokit.geom.empty(...).
-
makeLine–Alias for geokit.geom.line(...).
-
makePoint–Alias for geokit.geom.point(...).
-
makePolygon–Alias for geokit.geom.polygon(...).
-
partition–Partition a Polygon into some number of pieces whose areas should be close
-
point–Make a simple point geometry.
-
polygon–Creates an OGR Polygon object from a given set of points.
-
polygonizeMask–Create a geometry set from a matrix mask.
-
polygonizeMatrix–Create a geometry set from a matrix of integer values.
-
shift–Shift a polygon in longitudinal and/or latitudinal direction.
-
subTiles–Generate a collection of tiles which encompass the passed geometry.
-
tile–Generates a box corresponding to a tile used for "slippery maps".
-
tileAt–Generates a box corresponding to a tile at the coordinates 'x' and 'y'
-
tileize–Deconstruct a given geometry into a set of tiled geometries.
-
transform–Transform a geometry, or a list of geometries, from one SRS to another.
applyBuffer
¶
This function applies a buffer to any geom, avoiding edge issues with geoms near the SRS bounds. By shifting the geom to a zero longitude, geometry distortions are avoided when the buffered geom exceeds the bounds (i.e. antimeridian or latitudes of +/-90° e.g. in the case of EPSG:4326). Buffered geom areas extending over the bounds can either be clipped off or shifted to the respective "other end of the map". If the buffer is applied in a different (e.g. metric) EPSG, latitudinal overlaps will always be clipped.
geom : osgeo.ogr.Geometry Geometry to be buffered. buffer : int, float The buffer value to be applied to the geom, in unit of the SRS unless 'bufferInEPSG6933' is True, then always in meters. srs : Anything acceptable to geokit.srs.loadSRS(); optional Allows to specify an EPSG integer code or an osgeo.osr.SpatialReference instance to define the SRS in which the buffer will be applied, then in the unit of the specified EPSG. If e.g. 6933 is given, the buffer will be applied in meters in a metric system. Passing "laea" (case-insensitive) will generate a geometry-centered, metric Lambert Azimuthal Equal Area system in which the buffer will be applied. By default False, i.e. the original SRS of the geom will be used. split : str, optional 'shift' : shift areas that exceed the antimeridian line to the other end (default) 'clip' : remove/clip polygon parts that exceed the antimeridian 'none' : do not split geoms at all that cross the antimeridian
Source code in geokit/core/geom.py
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 | |
box
¶
Make an ogr polygon object from extents.
Parameters:
-
(*args¶4 numeric argument, or one tuple argument with 4 numerics, default:()) –The X_Min, Y_Min, X_Max and Y_Max bounds of the box to create
-
(srs¶Anything acceptable to geokit.srs.loadSRS(); optional, default:4326) –The srs of the point to create * If not given, longitude/latitude is assumed * srs MUST be given as a keyword argument
Returns:
-
Geometry–
Example:
box(xMin, yMin, xMax, yMax [, srs]) box( (xMin, yMin, xMax, yMax) [, srs])
Source code in geokit/core/geom.py
convertGeoJson
¶
convertGeoJson(geojson, srs=3857)
Make a geometry from a well known text (WKT) string.
TODO: UPDATE!!!
Parameters:
-
(wkt¶str) –The WKT string to convert
-
(srs¶Anything acceptable to geokit.srs.loadSRS(); optional, default:3857) –The srs of the geometry to create
Source code in geokit/core/geom.py
convertWKT
¶
Make a geometry from a well known text (WKT) string.
Parameters:
-
(wkt¶str) –The WKT string to convert
-
(srs¶Anything acceptable to geokit.srs.loadSRS(); optional, default:None) –The srs of the geometry to create
Source code in geokit/core/geom.py
divideMultipolygonIntoEasternAndWesternPart
¶
Multipolygons spanning the antimeridian (this includes polygons that are split at the antimeridian, with the Western half shifted Eastwards by 360° longitude) are separated into a part East and West of the antimeridian by identifying the largest longitudinal gap between any of the sub polygons and dividing the sub polys into one Eastern and one Western polygon list which is returned as multipolygons. NOTE: This function only works for already shifted subpolygons with an overall envelope between -180° and +180° longitude.
Parameters:
-
(geom¶Geometry) –The geometry to split. Must be a MultiPolygon.
-
(side¶str, default:'both') –'left' or 'right' to return the left or right side of the antimeridian 'main' to return the side with the largest area 'both' to return both sides as a tuple (left, right)
Source code in geokit/core/geom.py
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 | |
drawGeoms
¶
drawGeoms(
geoms: Geometry | list[Geometry] | DataFrame | ndarray,
srs: srs_input | None = None,
ax: None | Axes | AxHands = None,
simplificationFactor: numeric | None = 5000,
colorBy: str | None = None,
figsize: tuple[numeric, numeric] = (12, 12),
xlim: tuple[numeric, numeric] | None = None,
ylim: tuple[numeric, numeric] | None = None,
fontsize: int = 16,
hideAxis: bool = False,
cbarTitle=None,
vmin=None,
vmax=None,
cmap="viridis",
cbargs: dict | None = None,
**mplArgs,
) -> AxHands
Draw geometries onto a matplotlib figure.
- Each geometry type is displayed as an appropriate plotting type -> Points/ Multipoints are displayed as points using plt.plot(...) -> Lines/ MultiLines are displayed as lines using plt.plot(...) -> Polygons/ MultiPolygons are displayed as patches using the descartes library
- Each geometry can be given its own set of matplotlib plotting parameters
Notes
This function does not call plt.show() for the final display of the figure. This must be done manually after calling this function. Otherwise plt.savefig(...) can be called to save the output somewhere.
Sometimes geometries will disappear because of the simplification procedure. If this happens, the procedure can be avoided by setting simplificationFactor to None. This will take much more memory and will take longer to plot, however
Parameters:
-
(geoms¶Geometry or [Geometry] or DataFrame) –The geometries to be drawn * If a DataFrame is given, the function looks for geometries under a columns named 'geom' * plotting arguments can be given by adding a column named 'MPL:*' where '*' stands in for the argument to be added - For geometries that should ignore this argument, set it as None
-
(srs¶Anything acceptable to geokit.srs.loadSRS(); optional, default:None) –The srs in which to draw each geometry * If not given, longitude/latitude is assumed * Although geometries can be given in any SRS, it is very helpful if they are already provided in the correct SRS
-
(ax¶matplotlib axis; optional, default:None) –The axis to draw the geometries on * If not given, a new axis is generated and returned
-
(simplificationFactor¶float; optional, default:5000) –The level to which geometries should be simplified. It can be thought of as the number of vertices allowed in either the X or Y dimension across the figure * A higher value means a more detailed plot, but may take longer to draw
-
(colorBy¶str; optional, default:None) –The column in the geoms DataFrame to color by * Only useful when geoms is given as a DataFrame
-
(figsize¶(int, int); optional, default:(12, 12)) –The figure size to create when generating a new axis * If resultign figure looks weird, altering the figure size is your best bet to make it look nicer
-
(xlim¶(float, float); optional, default:None) –The x-axis limits
-
(ylim¶(float, float); optional, default:None) –The y-axis limits
-
(fontsize¶int; optional, default:16) –A base font size to apply to tick marks which appear * Titles and labels are given a size of 'fontsize' + 2
-
(hideAxis¶bool; optional, default:False) –Instructs the created axis to hide its boundary * Only useful when generating a new axis
-
(cbarTitle¶str; optional, default:None) –The title to give to the generated colorbar * If not given, but 'colorBy' is given, the same string for 'colorBy' is used * Only useful when 'colorBy' is given
-
(vmin¶float; optional, default:None) –The minimum value to color * Only useful when 'colorBy' is given
-
(vmax¶float; optional, default:None) –The maximum value to color * Only useful when 'colorBy' is given
-
(cmap¶str or matplotlib ColorMap; optional, default:'viridis') –The colormap to use when coloring * Only useful when 'colorBy' is given
-
(cbax¶matplotlib axis; optional) –An explicitly given axis to use for drawing the colorbar * If not given, but 'colorBy' is given, an axis for the colorbar is automatically generated
-
(cbargs¶dict; optional, default:None) –keyword arguments to pass on when creating the colorbar
-
–**mplArgs¶All other keyword arguments are passed on to the plotting functions called for each geometry * Will be applied to ALL geometries. Be careful since this can cause errors when plotting geometries of different types
Returns:
-
A namedtuple containing:–'ax' -> The map axis 'handles' -> All geometry handles which were created in the order they were drawn 'cbar' -> The colorbar handle if it was drawn
Source code in geokit/core/geom.py
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 | |
empty
¶
empty(gtype, srs=None)
Make a generic OGR geometry of a desired type.
Not for the feint of heart
Parameters:
-
(gtpe¶str) –The geometry type to make * Point, MultiPoint, Line, MultiLine, Polygon, MultiPolygon, etc...
-
(srs¶Anything acceptable to geokit.srs.loadSRS(); optional, default:None) –The srs of the geometry to create
Returns:
-
Geometry–
Source code in geokit/core/geom.py
extractVerticies
¶
Get all vertices found on the geometry as a Nx2 numpy.ndarray.
Source code in geokit/core/geom.py
fixOutOfBoundsGeoms
¶
This function allows to deal with polygons that protrude over the SRS bounds at +/-180° longitude respectively +/-90° latitude. Polygon areas that exceed those bounds are either clipped or shifted to the "opposite end of the map" with shapes at the poles being inverted and shifted by 180° to create a "fold-over" effect.
geom : osgeo-ogr.Geometry Geometry to fix. how : str, optional The way how to deal with sub shapes extending over the bounds: 'shift' : split off and shift to the "opposite end of the map" 'clip' : clip and remove extending shapes completely
Source code in geokit/core/geom.py
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 | |
flatten
¶
Flatten a list of geometries into a single geometry object.
Combine geometries by iteratively union-ing neighbors (according to index) * example, given a list of geometries (A,B,C,D,E,F,G,H,I,J): [ A B C D E F G H I J ] [ AB CD EF GH IJ ] [ ABCD EFGH IJ ] [ ABCDEFGH IJ ] [ ABCDEFGHIJ ] <- This becomes the resulting geometry
Example:
* A list of Polygons/Multipolygons will become a single Multipolygon
* A list of Linestrings/MultiLinestrings will become a single MultiLinestring
Source code in geokit/core/geom.py
line
¶
line(points, srs=4326)
Creates an OGR Line object from a given set of points.
Parameters:
-
(Points¶[(x,y), ], Nx2 numpy.ndarray or list of osgeo.ogr.Geometry points.) –The points defining the line
-
(srs¶Anything acceptable to geokit.srs.loadSRS(); optional, default:4326) –The srs of the line to create
Returns:
-
Geometry–
Source code in geokit/core/geom.py
makeBox
¶
makeEmpty
¶
makeLine
¶
makePoint
¶
makePolygon
¶
partition
¶
Partition a Polygon into some number of pieces whose areas should be close to the targetArea.
WARNING: Not tested for several version. Will probably be removed later
Inputs: geom : The geometry to partition - a single ogr Geometry object of POLYGON type
targetArea - float : The ideal area of each partition
* Most of the geometries will be around this area, but they can also be anywhere in the range 0 and 2x
growStep - float : The incremental buffer to add while searching for a suitable partition
* Choose carefully!
- A large growStep will make the algorithm run faster
- A small growStep will produce a more accurate result
* If no growStep is given, a decent one will be calculated
Source code in geokit/core/geom.py
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 | |
point
¶
Make a simple point geometry.
Parameters:
-
(*args¶(numeric, numeric or (numeric, numeric)), default:()) –The X and Y coordinate of the point to create
-
(srs¶Anything acceptable to geokit.srs.loadSRS(); optional, default:'latlon') –The srs of the point to create * If not given, longitude/latitude is assumed * srs MUST be given as a keyword argument
Returns:
-
Geometry–
Example:
point(x, y [,srs]) point( (x, y) [,srs] )
Source code in geokit/core/geom.py
polygon
¶
Creates an OGR Polygon object from a given set of points.
Parameters:
-
(outerRing¶[(x,y), ] or [ogr.Geometry, ] or Nx2 numpy.ndarray) –The polygon's outer edge
-
(*args¶[(x,y), ] or [ogr.Geometry, ] or Nx2 numpy.ndarray, default:()) –The inner edges of the polygon * Each input forms a single edge * Inner rings cannot interset the outer ring or one another * NOTE! For proper drawing in matplotlib, inner rings must be given in the opposite orientation as the outer ring (clockwise vs counterclockwise)
-
(srs¶Anything acceptable to geokit.srs.loadSRS(); optional, default:'default') –The srs of the polygon to create. By default "default", i.e. if point geometries are passed, srs will be extracted from first point of outer ring, if points are passed as (x, y) tuples, EPSG:4326 will be assigned by default unless given otherwise. If given as None, no srs will be assigned
Returns:
-
Geometry–
Example:
Make a diamond cut out of a box...
box = [(-2,-2), (-2,2), (2,2), (2,-2), (-2,-2)] diamond = [(0,1), (-0.5,0), (0,-1), (0.5,0), (0,1)]
geom = polygon( box, diamond )
Source code in geokit/core/geom.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
polygonizeMask
¶
Create a geometry set from a matrix mask.
Each True-valued group of pixels will be converted to a geometry
Parameters:
-
(mask¶matrix_like) –The mask which will be turned into a geometry set * Must be 2 dimensional * Must be boolean type * True values are interpreted as 'in the geometry'
-
(bounds¶(xMin, yMin, xMax, yMax) or Extent, default:None) –Determines the boundary context for the given mask and will scale the resulting geometry's coordinates accordingly * If a boundary is not given, the geometry coordinates will correspond to the mask's indices * If the boundary is given as an Extent object, an srs input is not required
-
(srs¶Anything acceptable to geokit.srs.loadSRS(); optional, default:None) –The srs of the geometries to create
-
(flat¶bool, default:True) –If True, flattens the resulting geometries into a single geometry
-
(shrink¶bool, default:True) –If True, shrink all geoms by a tiny amount in order to avoid geometry overlapping issues * The total amount shrunk should be very very small * Generally this should be left as True unless it is ABSOLUTELY necessary to maintain the same area
Returns:
-
If 'flat' is True: ogr.Geometry– -
else([Geometry]) –
Source code in geokit/core/geom.py
polygonizeMatrix
¶
polygonizeMatrix(
matrix: ndarray,
bounds: tuple[numeric, numeric, numeric, numeric]
| None = None,
srs: srs_input | None = None,
flat: bool = False,
shrink: bool = True,
_raw: bool = False,
) -> DataFrame | tuple[list, list]
Create a geometry set from a matrix of integer values.
Each unique-valued group of pixels will be converted to a geometry
Parameters:
-
(matrix¶matrix_like) –The matrix which will be turned into a geometry set * Must be 2 dimensional * Must be integer or boolean type
-
(bounds¶(xMin, yMin, xMax, yMax) or Extent, default:None) –Determines the boundary context for the given matrix and will scale the resulting geometry's coordinates accordingly * If a boundary is not given, the geometry coordinates will correspond to the mask's indices * If the boundary is given as an Extent object, an srs input is not required
-
(srs¶Anything acceptable to geokit.srs.loadSRS(); optional, default:None) –The srs context for the given matrix and of the geometries to create
-
(flat¶bool, default:False) –If True, flattens the resulting geometries which share a contiguous matrix value into a single geometry object
-
(shrink¶bool, default:True) –If True, shrink all geoms by a tiny amount in order to avoid geometry overlapping issues * The total amount shrunk should be very very small * Generally this should be left as True unless it is ABSOLUTELY necessary to maintain the same area
-
(_raw¶bool, default:False) –return a tuple with with two lists instead of a data frame. The first list contains the The contiguous-valued geometries and the second list the value the value for each geometry
Returns:
-
pandas.DataFrame -> With columns:–'geom' -> The contiguous-valued geometries 'value' -> The value for each geometry
-
| tuple[ list | list ]– -
The first list contains the contiguous-valued geometries. The seconds– -
list contains the value for each geometry.–
Source code in geokit/core/geom.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | |
shift
¶
Shift a polygon in longitudinal and/or latitudinal direction.
Inputs: geom : The geometry to be shifted - a single ogr Geometry object of POINT, LINESTRING, POLYGON or MULTIPOLYGON type - NOTE: Accepts only 2D geometries, z value must be zero.
lonShift - (int, float) : The shift in longitudinal direction in units of the geom srs, may be positive or negative
latShift - (int, float) : The shift in latitudinal direction in units of the geom srs, may be positive or negative
Returns :
osgeo.ogr.Geometry object of the input type with shifted coordinates
Source code in geokit/core/geom.py
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 | |
subTiles
¶
subTiles(geom, zoom, checkIntersect=True, asGeom=False)
Generate a collection of tiles which encompass the passed geometry.
Parameters:
-
(geom¶Geometry) –The geometry to be analyzed
-
(zoom¶int) –The zoom level to generate tiles on
-
(checkIntersect¶bool, default:True) –If True, only tiles which overlap the given geometry are returned
-
(asGeom¶bool, default:False) –If True, geometry object corresponding to each tile is yielded, instead of (xi,yi,zoom) tuples
Returns:
-
If asGeom is False: Generates (xi, yi, zoom) tuples– -
If asGeom is True: Generates Geometry objects–
Source code in geokit/core/geom.py
tile
¶
Generates a box corresponding to a tile used for "slippery maps".
Parameters:
-
(xi¶int) –The tile's X-index - Range depends on zoom value
-
(yi¶int) –The tile's Y-index - Range depends on zoom value
-
(zoom¶int) –The tile's zoom index - Range is between 0 and 18
Returns:
-
Geometry–
Source code in geokit/core/geom.py
tileAt
¶
Generates a box corresponding to a tile at the coordinates 'x' and 'y' in the given srs,.
Parameters:
-
(x¶float) –The X coordinate to search for a tile around
-
(y¶float) –The Y coordinate to search for a tile around
-
(zoom¶int) –The tile's zoom index - Range is between 0 and 18
-
(srs¶anything acceptable to SRS.loadSRS) –The SRS of the given 'x' & 'y' coordinates
Returns:
-
Geometry–
Source code in geokit/core/geom.py
tileize
¶
Deconstruct a given geometry into a set of tiled geometries.
Returns: Generator of ogr.Geometry objects
Source code in geokit/core/geom.py
transform
¶
transform(
geoms,
toSRS,
fromSRS=None,
revert360degProj=False,
segment=None,
) -> Geometry | list[Geometry]
Transform a geometry, or a list of geometries, from one SRS to another.
Parameters:
-
(geoms¶Geometry or [Geometry]) –The geometry or geometries to transform * All geometries must have the same spatial reference
-
(toSRS¶Anything acceptable to geokit.srs.loadSRS()) –The srs of the output geometries
-
(fromSRS¶Anything acceptable to geokit.srs.loadSRS(); optional, default:None) –The srs of the input geometries * Only needed if an SRS cannot be inferred from the geometry inputs or is, for whatever reason, the geometry's SRS is wrong
-
(revert360degProj¶bool; optional, default:False) –If True, will revert the 360° shift that is applied by PROJ to points beyond the antimeridian when transforming to EPSG:4326 to avoid invalid, distorted geometries when points are only partially shifted. Will then devliver a geometry that may partially be outside the -180° to 180° longitude range. By default False.
-
(segment¶float; optional, default:None) –An optional segmentation length to apply to the input geometries BEFORE transformation occurs. The input geometries will be segmented such that no line segment is longer than the given segment size * Units are in the input geometry's native unit * Use this for a more detailed transformation!
Returns:
-
Geometry or [Geometry]–
Note:
When inferring the SRS from the given geometries, only the FIRST geometry is checked for an existing SRS
Source code in geokit/core/geom.py
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 | |