Skip to content
Snippets Groups Projects
Commit 4740c6be authored by Wit, Allard de's avatar Wit, Allard de
Browse files

Added checks for proper lat/lon.

parent 0c31d639
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
# Allard de Wit (allard.dewit@wur.nl), October 2021
"""Grompy is a tool to process and access parcel-based satellite observations from GroenMonitor.nl.
"""
__version__ = "1.6.1"
__version__ = "1.6.2"
from .dap import DataAccessProvider
from .cmd import cli
......
......@@ -233,7 +233,11 @@ class DataAccessProvider:
d[dataset_name] = df
c = SimpleNamespace(**d)
assert (50 < parcel_info.latitude < 54), f"Latitude out of range {parcel_info.latitude}, did you invert x and y?"
assert (3.0 < parcel_info.longitude < 7.5), f"Longitude out of range {parcel_info.longitude}, did you invert x and y?"
yield parcel_info, c
rows = r.fetchmany(100)
def __len__(self):
......
......@@ -13,7 +13,7 @@ import numpy as np
import yaml
import duckdb
from .util import prepare_db, make_path_absolute, get_latlon_from_RD
from .util import prepare_db, make_path_absolute, get_latlon_from_RD, check_naam, check_PC4
class CSVLoadingError(Exception):
......@@ -53,7 +53,9 @@ def load_parcel_info(grompy_yaml, gpkg_fname, counts_file_10m, counts_file_20m,
r = []
for row in df.itertuples():
x, y = float(row.geometry.centroid.x), float(row.geometry.centroid.y)
lon, lat = get_latlon_from_RD(x, y)
lat, lon = get_latlon_from_RD(x, y)
assert (50 < lat < 54), f"Latitude out of range {lat}, did you invert x and y?"
assert (3.0 < lon < 7.5), f"Longitude out of range {lon}, did you invert x and y?"
r.append({"fieldid": row.Index, "latitude": lat, "longitude":lon, "rdx": x, "rdy": y})
df_latlon = pd.DataFrame(r).set_index("fieldid")
df = df.join(df_latlon)
......@@ -82,15 +84,15 @@ def load_parcel_info(grompy_yaml, gpkg_fname, counts_file_10m, counts_file_20m,
"rdy": df.rdy,
"longitude": df.longitude,
"latitude": df.latitude,
"cat_gewasc": df.cat_gewasc.apply(str),
"cat_gewasc": df.cat_gewasc.apply(check_naam),
"gws_gewasc": df.gws_gewasc.astype(np.int32),
"provincie": df.provincie.apply(str),
"gemeente": df.gemeente.apply(str),
"regio": df.regio.apply(str),
"pc4": df.PC4.apply(lambda pc4: str(int(pc4))),
"provincie": df.provincie.apply(check_naam),
"gemeente": df.gemeente.apply(check_naam),
"regio": df.regio.apply(check_naam),
"pc4": df.PC4.apply(check_PC4),
"AHN2": df.AHN2,
"woonplaats": df.woonplaats.apply(str),
"waterschap": df.waterschap.apply(str),
"woonplaats": df.woonplaats.apply(check_naam),
"waterschap": df.waterschap.apply(check_naam),
"S2_Tiles": df.S2_Tiles.apply(str),
"geometry": df.geometry
}, crs=df.crs)
......
......@@ -105,6 +105,8 @@ def open_DB_connection(grompy_yaml, dsn):
def get_latlon_from_RD(x, y, _cache={}):
"""Converts given X,Y in the Dutch RD coordinate system towards latitude longitude in WGS84
returns: (latitude, longitude)
For checking:
in RD coordinate system X, Y: 197903, 309096
should be in WGS84 latitude, longitude: 50.770195900951045, 5.995343676754713
......@@ -128,4 +130,20 @@ def check_grompy_version(grompy_yaml):
msg = f"grompy.yaml ({v1}) does not match grompy version ({v2})! " \
"Generate a new grompy.yaml file with `grompy init` " \
"and adapt it."
raise RuntimeError(msg)
\ No newline at end of file
raise RuntimeError(msg)
def check_PC4(postal_code):
try:
pc4 = str(int(postal_code))
except ValueError as e:
pc4 = "0000"
return pc4
def check_naam(name):
try:
n = str(name)
except ValueError as e:
n = "Unknown"
return n
......@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
[project]
name = "grompy"
version = "1.6.1"
version = "1.6.2"
description = "GROMPY is a tool for storing and accessing Groenmonitor satellite time-series for agricultural parcels."
authors = [
{name = "Allard de Wit", email = "allard.dewit@wur.nl"},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment