KipCrossing / geotiff

A noGDAL tool for reading and writing geotiff files
GNU Lesser General Public License v2.1
216 stars 23 forks source link

[Feature] coord converter efficency improvemet #21

Closed KipCrossing closed 3 years ago

KipCrossing commented 3 years ago

Adds

        if crs_code == 4326:
            return(xx, yy)

to bypass the transformer and increase conversion efficiency.

    def _convert_to_wgs_84(self, crs_code: int, xxyy: Tuple[float, float]) -> Tuple[float, float]:
        xx: float = xxyy[0]
        yy: float = xxyy[1]
        if crs_code == 4326:
            return(xx, yy)
        crs_4326: CRS = CRS("WGS84")
        crs_proj: CRS = CRS.from_epsg(crs_code)
        transformer: Transformer = Transformer.from_crs(crs_proj, crs_4326, always_xy=True)
        return(transformer.transform(xx, yy))
KipCrossing commented 3 years ago

There's a big efficiency improvment by converting entire arrays:

lon_vals, lat_vals = transformer.transform(x_vals, y_vals)

Perhaps a feature could be

.get_x_array() .get_y_array()

Thats gets the 2d array of the converted coords