OpenDrift / opendrift

Open source framework for ocean trajectory modelling
https://opendrift.github.io
GNU General Public License v2.0
246 stars 120 forks source link

geojson polygon #483

Closed John-Luick closed 3 years ago

John-Luick commented 3 years ago

Hi, my attempt to use example_seed_geojson.py resulted in the error "Openoil object has no attribute 'seed_from_geojson'". Any suggestions?

Earlier I tried using a shapefile (with seed_from_shapefile) but OpenDrift would not recognise the various shapefiles I tried (gave various different errors). Shapefiles are obviously more useful if you have more than a small number of points in the polygon. I tried shapefiles created by both Matlab and ArcGIS. Both versions were successfully tested by importing the shapefiles into other software, but OpenDrift did not like them. I tried both UTM and lat/lon coordinates, same result.

It would be good to get the geojson thing going, but at the same time, any hints on creating a shapefile that opendrift will read would be of interest. Better yet, since shapefiles are the devil's handiwork (unlike netcdf, for example, there is no requirement for specifying units, map datum, or anything else, so it is total guesswork), if there are other ways of specifying a polygon (one with hundreds or thousands of points), that would also be of interest.

knutfrode commented 3 years ago

Hi, If seed_from_geojson is not working, your OpenDrift repository seems to have become corrupted. You can check this with git status.

Here is the code for seed_from_shapefile, which is using GDAL/OGR: https://opendrift.github.io/_modules/opendrift/models/basemodel.html#OpenDriftSimulation.seed_from_shapefile It seems to work well for most "off-the-shelf" shapefiles I have tried so far. But if you can provide a non-working file, I can have a look at it. Otherwise you may try to insert some debug-lines to see what could be the problem.

knutfrode commented 3 years ago

Btw, both seed_from_geojson and seed_from_shapefile are in the end using seed_within_polygon, which you could also use directly if you have imported the polygons (lon, lat) into Python by other means: https://opendrift.github.io/_modules/opendrift/models/basemodel.html#OpenDriftSimulation.seed_within_polygon There is no limit to the length/number of polygons.

John-Luick commented 3 years ago

Thank you, Knut-Frode. In case anyone else wants to seed in a polygon, "o.seed_within_polygon", (used after using np.loadtext to read in a csv file containing polygon latitudes and longitudes), is very simple and straightforward, and works as advertised. I did look into GDAL/OGR, but decided that learning to use it is something I can leave for a future life, right after learning Pitjantjatjara (one of 363 Australian indigenous languages). Check out the list of drivers on gdal.org. I think there are more drivers than there are human languages.

gauteh commented 3 years ago

GDAL does have an impressive number of drivers! And I think you have your priorities straight! Anyway, this issue seems to be resolved now?