Skip to content
Permalink
Browse files

updated processor shell script and associated readme section

  • Loading branch information...
jonnyhuck committed Nov 9, 2017
1 parent cdb0824 commit b26fc6602140a73e65efaa1fd287a6f0e1265e42
BIN -2.12 MB Leh.png
Binary file not shown.
@@ -61,4 +61,47 @@ Here is the result:

![resulting geotiff](images/diff.png)

`python mapex.py -h` will give further information for now.
`python mapex.py -h` will give further information for now.

### Bulk Extraction and Shapefiles
**NB:** This step requires the **GDAL** binary installation

In most cases, you will want to extract many images at the same time and extract shapefiles rather than GeoTiffs. This can be achieved usng a simple shell script like this:

```bash
#!/bin/bash
# fix any spaces in file names
for f in *.jpg; do mv "$f" "${f// /_}"; done
# extract tifs and contours
for FILE in *.jpg
do
FILENEW=`echo $FILE | sed "s/.jpg/.tif/"`
echo python mapex.py -r reference_img.png -m reference_map.png -t $FILE -o $FILENEW -k 5 -b 30 -l 0.1 -c 90
python mapex.py -r holly50k.png -m holly_50kmap.png -t $FILE -o $FILENEW -k 5 -b 30 -l 0.1 -c 90
FILE2=`echo $FILENEW | sed "s/.tif/_tmp.shp/"` # tmp file to be reprojected then deleted
FILE3=`echo $FILENEW | sed "s/.tif/.shp/"` # result file
# make polygons from the raster
echo gdal_polygonize.py -q $FILENEW -f "ESRI Shapefile" $FILE2
gdal_polygonize.py -q $FILENEW -f "ESRI Shapefile" $FILE2
# fix the projection problem (not sure why this happens...)
echo ogr2ogr -f "ESRI Shapefile" -s_srs "EPSG:3857" -t_srs "EPSG:54004" -overwrite -where "DN = 0" $FILE3 $FILE2
ogr2ogr -f "ESRI Shapefile" -s_srs "EPSG:3857" -t_srs "EPSG:54004" -overwrite -where "DN = 0" $FILE3 $FILE2
# clean up the unwanted files
echo "cleaning..."
rm $FILE2
rm `echo $FILE2| sed "s/.shp/.dbf/"`
rm `echo $FILE2| sed "s/.shp/.shx/"`
rm `echo $FILE2| sed "s/.shp/.prj/"`
echo ""
done
echo "done."
```

An example of this is provided in [processor.sh](./processor.sh).
BIN -963 KB holly50k.png
Binary file not shown.
BIN -805 KB holly_50kmap.png
Binary file not shown.
File renamed without changes.
@@ -164,7 +164,7 @@ def toGeoTiff(geoData, w, h, filename):
parser.add_argument('-m','--map', help='the reference map', required = True)
parser.add_argument('-t','--target', help='the target image', required = True)
parser.add_argument('-o','--output', help='the name of the output file', required = False, default='out.tif')
parser.add_argument('-k','--kernel_size', help='the size of the kernel', required = False, default=7)
parser.add_argument('-k','--kernel_size', help='the size of the kernel', required = False, default=5)
parser.add_argument('-b','--border_size', help='the border size', required = False, default=50)
parser.add_argument('-l','--lowe_distance', help='the lowe distance threshold', required = False, default=0.5)
parser.add_argument('-c','--diff_threshold', help='the % threshold for image differencing', required = False, default=90)
@@ -0,0 +1,33 @@
#!/bin/bash

# fix any spaces in file names
for f in *.jpg; do mv "$f" "${f// /_}"; done

# extract tifs and contours
for FILE in *.jpg
do
FILENEW=`echo $FILE | sed "s/.jpg/.tif/"`
echo python mapex.py -r reference_img.png -m reference_map.png -t $FILE -o $FILENEW -k 5 -b 30 -l 0.1 -c 90
python mapex.py -r holly50k.png -m holly_50kmap.png -t $FILE -o $FILENEW -k 5 -b 30 -l 0.1 -c 90

FILE2=`echo $FILENEW | sed "s/.tif/_tmp.shp/"` # tmp file to be reprojected then deleted
FILE3=`echo $FILENEW | sed "s/.tif/.shp/"` # result file

# make polygons from the raster
echo gdal_polygonize.py -q $FILENEW -f "ESRI Shapefile" $FILE2
gdal_polygonize.py -q $FILENEW -f "ESRI Shapefile" $FILE2

# fix the projection problem (not sure why this happens...)
echo ogr2ogr -f "ESRI Shapefile" -s_srs "EPSG:3857" -t_srs "EPSG:54004" -overwrite -where "DN = 0" $FILE3 $FILE2
ogr2ogr -f "ESRI Shapefile" -s_srs "EPSG:3857" -t_srs "EPSG:54004" -overwrite -where "DN = 0" $FILE3 $FILE2

# clean up the unwanted files
echo "cleaning..."
rm $FILE2
rm `echo $FILE2| sed "s/.shp/.dbf/"`
rm `echo $FILE2| sed "s/.shp/.shx/"`
rm `echo $FILE2| sed "s/.shp/.prj/"`
echo ""
done

echo "done."
BIN -2.18 MB test.jpg
Binary file not shown.

0 comments on commit b26fc66

Please sign in to comment.
You can’t perform that action at this time.