4

I am working on mangroves in Sundarbans (Bangladesh / India), using Landsat pictures. I need to equalize them in reflectance, before classification, for the evolution of the biomass in this region. I have a mangroves' shapefile over this area, with +150 000 features (polygons). So far, the segmentation part and the classification part work well. However, to be able to equalize the pictures, I need to focus on the overlapping parts between this pictures. I succeeded in extracting the overlap between two pictures, and then having the shapefile corresponding to the boundaries of the overlap.

First, what I need to do is clipping the big mangroves' shapefile to the extent of an overlap between 2 images, so I can then compute the overlapping raster with only the mangroves parts to equalize these two pictures. I tried this following command :

ogr2ogr -f ESRI Shapefile -clipsrc extent.shp mangrove_clip.shp mangrove.shp

I am coding in python, but even on a direct command line request, this doesn't seem to work. Actually, I don't have any message to screen here because nothing is screened on the terminal, as if the command ran indefinitely... I know that on QGIS, there is the clip tool under "Vector > Geoprocessing Tools". This works perfectly, and it is really fast (less than 30s). The thing is that I need to script this because I have over 10 images on this area and I need to work on every overlap between every images, so doing it manually through QGIS is not feasible. Besides, I may have to re-use that for other parts of the world.

That's a pity that for the vector part, QGIS does not screen the corresponding command line like it does for the raster (filling the gdalwarp with its arguments for example, when you want to clip a raster). Does anybody know what's wrong with my ogr2ogr command ? i know that's a hard question considering I have no returned error message... What's the command QGIS is using ? I tried hard to find an answer but every topic ended with this ogr2ogr command as a solution.

And the command actually works for another shapefile...

Even if by letting the command run for 2 days, it worked, I don't think it's normal for it to take so long when QGIS does it in 30s.

Concerning the mangroves' shapefile (which looks to be the problem, but once again, it works with QGIS), it is a polygon shapefile, and my extent shapefile is also a polygon shapefile.

  • Are your mangroves and extent in the same spatial reference? Normally ogr2ogr with -clipsrc is extremely fast (even faster than Esri) which makes me think that there's a warp going on.. On scripting in python, have a look at subprocess.Popen to run a command line tool from python (and then process.wait() to wait for the command to finish before executing the next one) – Michael Stimson Jun 17 '15 at 1:05
  • Sure my both shapefiles are in the same crs. It works with QGIS (vector > geoprocessing tools > clip), in less than 30s. – Post. T. Jun 17 '15 at 16:37
  • 1
    The subprocess works when I am trying a different random shapefile, containing only 1 polygon in the attribute table however, to clip (different from the mangroves' one) Eventually, after letting the script run yesterday evening, the result is there, but it took 3,7 hours (I used time() to check). I also tried just the command line I posted in my first message, and I have the same result than with subprocess in python. But it is as long as with the python script, I'll give a try with popen but if it takes the same time in pure command line than in python, it should not change anything... – Post. T. Jun 17 '15 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.