-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Conversation
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? |
I agree. Have you tried checking via openlayers or proj in frontend? @NSUWAL123 |
Currently, only polygon is handled via frontend. I will try to handle multipolygon also. |
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. |
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. |
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:
And there is no point doing check_crs in every function where geojson is uploaded. So, I will refactor those. |
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). |
I'm wondering if OpenLayers has some functions already written to handle this too |
@spwoodcock openlayers support most of the geojson types natively so right now backend needs to do some handling with the provided geojson right ? |
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. 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 I think the frontend could handle that right? |
@spwoodcock yeah sure we can do that, Let's do that for now instead of requesting backend for the check. |
Closing, handled on the frontend: #1112 |
Updates