How to convert GIS rasters into vector polygons? - d3.js

How to turn raster GIS files (tiff) into .json ?
Bostock's example used some JSON data to feed his D3.geom.contour plugin. But how to convert a GIS raster, let's say a tiny 11px/15px tiff image, into a JSON.
Final .JSON code such: [EDIT: this is NOT the topojson format]
[
[103,104,104,105,105,106,106,106,107,107,106],
[104,104,105,105,106,106,107,107,107,107,107],
[104,105,105,106,106,107,107,108,108,108,108],
[105,105,106,106,107,107,108,108,109,109,109],
[105,106,106,107,107,108,108,109,109,110,110],
[106,106,107,107,107,108,109,109,110,110,111],
[106,107,107,108,108,108,109,110,110,111,112],
[107,107,108,108,109,109,110,110,112,113,114],
[107,108,108,109,109,110,111,112,114,115,116],
[107,108,109,109,110,110,110,113,115,117,118],
[107,108,109,109,110,110,110,112,115,117,119],
[108,108,109,109,110,110,110,112,115,118,121],
[108,109,109,110,110,111,112,114,117,120,124],
[108,109,110,110,110,113,114,116,119,122,126],
[108,109,110,110,112,115,116,118,122,124,128]
]
Note: .shp to .json: There is already a tutorial on how turning shapefiles into lighter topojson, but not useful to here.

I don't think you can do it directly, it's probably a several step process:
Process
Convert .tiff -> .shp
gdal_contour -a elev input.tif output.shp -i 10.0
Convert .shp -> .json (topojson)
topojson input.shp -o output.json
Resources
Be aware of TopoJSON Command Line ;
Tutorial: Working with Terrain Data in QGIS point out to GDAL utilities ;
gdal_contour builds vector contour lines from a raster elevation model.

Related

Using wildcards with "convert". Or "convert"ing a group of files

I regularly scan in my Homework for class. My scanner exports raw jpg files to usb, and from there I can use gimp to edit and save the files as a pdf. One time saver I've found is to export my multi-page homeworks as a .mng file and then use the convert function to turn it into a pdf. I do it this way because Gimp automatically merges all layers when exporting to a pdf.
convert HW.mng HW.pdf
this works well for individual files, but at the end of every week I can have dozens of files to convert.
I have tried using wildcards in the filenames for convert:
convert *.mng *.pdf
This always runs successfully and never throws an error, but never produces any pdfs.
Both
convert HW*.mng HW*.pdf
and
convert "HW*.mng" "HW*.pdf"
yeild the error
convert: unable to open image `HW*.pdf': Invalid argument # error/blob.c/OpenBlob/2712.
which I think means the error lies in exporting with a wildcard.
Is there any way to convert all of a specific file type to another using convert? Or should I try using a different program?
You can see this StackExchange post. The accepted answer basically does what you want.
for file in *.mng; do convert -input "$file" -output "${file/%mng/pdf}"; done
For convert in particular, use mogrify (which is part of ImageMagick as well) as suggested by Mark Setchell in a comment. mogrify can be used to edit/convert files in batches. The command for your case would be
mogrify -format pdf -- *.mng

Image Magick is generating black images while converting pdf to jpg

Image Magick version in use is 6.8.8.1.
Via command line on windows I am just trying to convert a *.pdf file into .jpg file using the following command
convert -density 100 -colorspace RGB "input.pdf" "output.jpg"
But the resulting output.jpg file is with a black image (there is no content). Any one out there could please guide on this ?
When you open this PDF-file by using a text-editor and it's header contains something like this:
%PDF-1.5
%¦éÏÄ
4 0 obj
<</Length 5 0 R/Filter /FlateDecode>>stream
....
....
then you have to decode this flat-encoded stream first before you can convert it to an image.
To solve this problem:
You can use the GUI-Tool pdftk free, set your environment-path to the bin-folder within the pdftk-folder and execute:
pdftk ENCODED_FILENAME.pdf output DECODED_FILENAME.pdf uncompress
in the shell to deflate/unzip this file.
Create a new file that is not encoded or zipped.
Hope this helps.
Set alpha flag to off in convert command.

Cannot open .dot file gvEdit

I cannot open the attached dot file in gvEdit.
I tried to convert it to png file
dot -Tpng final.dot > finalgraph.png
it gives me the following problem:
dot: graph is too large for cairo-renderer bitmaps. Scaling by 0.311296 to fit
dot: failure to create cairo surface: out of memory
My purpose is only to view the dot file, how should I resolve it?
The dot file is here:
https://www.dropbox.com/s/vt2q653x2x9jjbj/final.dot?dl=0

Motion Vector extraction from encoded video file

I am trying to extract motion vector data from an encoded mp4 file. In a previous post I found
an answer http://www.princeton.edu/~jiasic/cos435/motion_vector.c . But I am not able to run the code without errors . What are the other files that have to be included in the file ? I am a newbie here . So any help would be appreciated .
I had modified the source code of mplayer (ffmpeg) to extract motion vectors for any compressed video, I have uploaded the modified mplayer code which can be used for extracting motion vectors here http://www.cs.umd.edu/~bharat/modmplayer.zip
You need to do the following to extract motion vectors if you use the modified version of mplayer
./mplayer -nosound -fps 200 -vo null -lavdopts vismv=1 path_of_video_file 2> path_of_output_file.txt
Pre-compiled executable and some useful files are available in the outputs folder

combining different files with topojson at different simplification levels

I would like to combine three geojson files into one topojson file. two of these files are pretty straightforward shapefiles. they need no simplifying.
one of them is the 10m cultural natural earth vector file. it's geojson is 24.8mb. I need the 10m because i need small islands to remain on the map (though i'll likely simplify them out but retain them with --allow-empty).
is it possible to simplify the 10m cultural file with topojson, then combine it with the other two geojson files using topojson but without simplifying?
or is this a totally crooked approach, and i should be approaching in another way?
thanks for any help
You may simplify them separately and merge them.
Given you have your 3 shapefiles in your folder, you could use a makefile a bit such :
#Merge:
final.json: map1.json map2.json world10m.json
topojson --id-property none --allow-empty -o final.json -- map1.json map2.json world10m_s.json
# Simplify:
world10m_s.json -- world10m.json
topojson --id-property none --allow-empty --simplify 0.5 -p name=Name -o world10m_s.json -- world10m.json
# SHP2JSON
world10m.json: world10m.shp
ogr2ogr -f GeoJSON world10m.json world10m.shp
map1.json: map1.shp
ogr2ogr -f GeoJSON map1.json map1.shp
map2.json: map2.shp
ogr2ogr -f GeoJSON map2.json map2.shp
Note: There are plenty of good reasons Why Use Make
Note2: Since topojson script also accept .shp for input, we could skip the #SHP2JSON task.

Resources