Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check coordinate system of project AOI #1061

Closed
wants to merge 2 commits into from
Closed

Conversation

Sujanadh
Copy link
Collaborator

Updates

  1. Previously, the coordinate system of the uploaded AOI was verified on the frontend. However, it is now preferable to perform this check on the backend. Consequently, a new API has been created specifically for validating the coordinate system of the uploaded GeoJSON.
  2. Subsequently, it is recommended to invoke this API immediately after uploading the GeoJSON.

@Sujanadh Sujanadh requested a review from nrjadkry December 26, 2023 04:25
@Sujanadh Sujanadh self-assigned this Dec 26, 2023
@github-actions github-actions bot added the backend Related to backend code label Dec 26, 2023
@Sujanadh Sujanadh changed the title Check coordinate system of upload AOI Check coordinate system of project AOI Dec 26, 2023
@spwoodcock
Copy link
Member

Do we need a new endpoint for this? The project creation already makes quite a lot of calls, adding load to the server.

We added CRS checking before as a low priority item. GeoJSON in CRS other than EPSG:4326 is very uncommon.

And how come CRS checking is preferred on the backend? I would actually argue that checking via OpenLayers and proj on the frontend is preferable. We don't even need reprojection, just a simple check.

@susmina94 do you have thoughts?

@Sujanadh
Copy link
Collaborator Author

I agree. Have you tried checking via openlayers or proj in frontend? @NSUWAL123

@NSUWAL123
Copy link
Contributor

Currently, only polygon is handled via frontend. I will try to handle multipolygon also.

@Sujanadh
Copy link
Collaborator Author

For now, geojson was checked using manual procedure that is whether the coordinate of polygon lies between -90 to +90 or -180 to +180. Checking like this will probably slows down. That's why i created endpoint to avoid that in frontend.

@spwoodcock
Copy link
Member

If we are making an api call anyway, then it's ok to check crs in the backend (as we do currently when we upload geojson files).

I would be surprised if the frontend struggles to calculate if a polygon is inside bounds though. If the polygon has thousands of vertices to check it would make sense. But the backend wouldn't be much quicker unless the calculation is vectorised.

It it's an issue and the user experience is too bad then we should reconsider doing the crs checks.

@Sujanadh
Copy link
Collaborator Author

Sujanadh commented Dec 26, 2023

okay, lets handle it on the frontend side. @NSUWAL123 will do that, he will check every possible type of EPSG: 4326 for both polygon and multipolygon which might be as follows:

  1. "urn:ogc:def:crs:OGC:1.3:CRS84",
  2. "urn:ogc:def:crs:EPSG::4326",
    Or same like before, checking coordinates (lat between -90 to 90 and lon between -180 to 180) but if we are taking it seriously then, it only wont be enough since other crs like NAD 83, EPSG: 3395 and so on also have similar range for lat lon.

And there is no point doing check_crs in every function where geojson is uploaded. So, I will refactor those.

@spwoodcock
Copy link
Member

Thanks for the feedback @Sujanadh 👍

I agree it's difficult to accurately assess the CRS without writing lots of code.

For cases when the user has immediate feedback / the geom is displayed on the map, viewing that the geom is incorrectly placed is validation enough.

We only really need CRS checking where passing an uploaded geojson to a backend function might break it / make it behave unexpectedly.

A geojson with the crs key isn't overly common, but checking the coord bounds is a good rough check for EPSG:4326 (although not perfect like you say).

@spwoodcock
Copy link
Member

I'm wondering if OpenLayers has some functions already written to handle this too

@varun2948
Copy link
Contributor

@spwoodcock openlayers support most of the geojson types natively so right now backend needs to do some handling with the provided geojson right ?

@spwoodcock
Copy link
Member

spwoodcock commented Jan 9, 2024

OpenLayers does support multiple coordinate systems, but by default can only load EPSG:3857 and EPSG:4326. For others, the proj code needs to be loaded, e.g.

import proj4 from 'proj4';
import {register} from 'ol/proj/proj4.js';
import {get as getProjection} from 'ol/proj.js';
proj4.defs('EPSG:21781',
  '+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 ' +
  '+x_0=600000 +y_0=200000 +ellps=bessel ' +
  '+towgs84=660.077,13.551,369.344,2.484,1.783,2.939,5.66 +units=m +no_defs');
register(proj4);
const swissProjection = getProjection('EPSG:21781');

So you really need a good idea of what coordinate systems will be provided, to have support for them.
It's difficult to cover all possible coordinate systems, and honestly it quite a niche thing to require in our application (more for scientific / research uses).

As of now we just need EPSG:4326 support.

So the idea here is just a simple check to see if the coordinates are in bounds: -180.0 -90.0
180.0 90.0.

I think the frontend could handle that right?
(and provide an error if the geojson is not in the bounds)

@varun2948
Copy link
Contributor

@spwoodcock yeah sure we can do that, Let's do that for now instead of requesting backend for the check.

@spwoodcock
Copy link
Member

Closing, handled on the frontend: #1112

@spwoodcock spwoodcock closed this Jan 19, 2024
@spwoodcock spwoodcock deleted the feat-check-crs branch January 19, 2024 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Related to backend code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants