Skip to content

Commit e95612c

Browse files
committed
added sampling to tiling string; added str and repr for all projected geometries
1 parent 35aa2cc commit e95612c

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

docs/guides/geometry.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"from pytileproj import ProjCoord\n",
4646
"\n",
4747
"proj_coord = ProjCoord(x=25, y=10, crs=pyproj.CRS.from_epsg(3857))\n",
48-
"proj_coord"
48+
"print(proj_coord) # noqa: T201"
4949
]
5050
},
5151
{
@@ -90,7 +90,7 @@
9090
"\n",
9191
"geom = Polygon([(1, 1), (10, 2), (8, 7), (2, 4)])\n",
9292
"proj_geom = ProjGeom(geom=geom, crs=pyproj.CRS.from_epsg(27701))\n",
93-
"proj_geom"
93+
"print(proj_geom) # noqa: T201"
9494
]
9595
},
9696
{
@@ -131,7 +131,7 @@
131131
"name": "python",
132132
"nbconvert_exporter": "python",
133133
"pygments_lexer": "ipython3",
134-
"version": "3.12.12"
134+
"version": "3.12.3"
135135
}
136136
},
137137
"nbformat": 4,

src/pytileproj/projgeom.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,39 @@ class ProjCoord:
6262
y: float
6363
crs: pyproj.CRS
6464

65+
def __repr__(self) -> str:
66+
"""Short string representation."""
67+
return f"{self.__class__.__name__}({self.x}, {self.y})"
68+
69+
def __str__(self) -> str:
70+
"""Extensive string representation."""
71+
n_chars = len(self.__class__.__name__)
72+
return (
73+
f"{self.__class__.__name__} \n{'-' * n_chars} \n"
74+
f"X: \n{self.x} \n"
75+
f"Y: \n{self.y} \n"
76+
f"Projection: \n{self.crs.to_proj4()}"
77+
)
78+
6579

6680
@dataclass(frozen=True)
6781
class GeogCoord(ProjCoord):
6882
crs: pyproj.CRS = GEOG_CRS
6983

84+
def __repr__(self) -> str:
85+
"""Short string representation."""
86+
return f"{self.__class__.__name__}({self.x}, {self.y})"
87+
88+
def __str__(self) -> str:
89+
"""Extensive string representation."""
90+
n_chars = len(self.__class__.__name__)
91+
return (
92+
f"{self.__class__.__name__} \n{'-' * n_chars} \n"
93+
f"X: \n{self.x} \n"
94+
f"Y: \n{self.y} \n"
95+
f"Projection: \n{self.crs.to_proj4()}"
96+
)
97+
7098

7199
def convert_geom(arg: str | shapely.Geometry) -> shapely.Geometry:
72100
return swkt.loads(arg) if isinstance(arg, str) else arg
@@ -87,6 +115,19 @@ def serialize(self) -> dict:
87115
"""Serialise/encode class variables."""
88116
return {"geom": self.geom.wkt, "crs": self.crs.to_wkt()}
89117

118+
def __repr__(self) -> str:
119+
"""Short string representation."""
120+
return f"{self.__class__.__name__}({self.geom})"
121+
122+
def __str__(self) -> str:
123+
"""Extensive string representation."""
124+
n_chars = len(self.__class__.__name__)
125+
return (
126+
f"{self.__class__.__name__} \n{'-' * n_chars} \n"
127+
f"Geometry: \n{self.geom} \n"
128+
f"Projection: \n{self.crs.to_proj4()}"
129+
)
130+
90131

91132
class GeogGeom(ProjGeom):
92133
crs: pyproj.CRS = pyproj.CRS.from_epsg(GEOG_EPSG)

src/pytileproj/tiling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def to_ogc_standard(self) -> dict:
172172

173173
def __repr__(self) -> str:
174174
"""Short string representation."""
175-
return f"{self.__class__.__name__}({self.name})"
175+
return f"{self.__class__.__name__}({self.name}, {self.sampling})"
176176

177177
def __str__(self) -> str:
178178
"""Extensive string representation."""

0 commit comments

Comments
 (0)