Extracting path data from an SVG map to use in RaphaelJs - dictionary

I'm trying to build an an interactive map using RaphaelJS (e.g. http://raphaeljs.com/australia.html). Please check the source. It requires map path data to input. There is no clear explanation anywhere about how to obtain this information, other than the fact that illustrator or inkscape are capable of doing it.
I'm looking to obtain "States" path data from this India map: http://en.wikipedia.org/wiki/File:India-locator-map-blank.svg

well, this one is easy. SVG is just a simple XML file. So you don't have to "extract" anything via Illustrator.
Just open the SVG in any text editor and it's all there! (the path data string you can use with RaphaelJS path-function is held in the d-attribute of the path nodes).
Watch our for copyright issues when using SVG files of others ;)
Skunks

You could also use a converter like Ready.Set.Raphael to extract the paths for you and create the javascript output. It's a real time saver!

For older SVG files the path data will need to be optimized for RaphaelJS. Open the file in Inkspace and save as Optimized AVG. If you have an AVG file that opens as a blank image in Adobe Illustrator, edit the file with a text editor and set the first two values of the viewBox to 0,0. Both steps may be required when working with map AVG files from Wikipedia.

Related

Is there a way to (de)serialize and hardcode an image in a R-markdown file?

I want to load an image into a .rmd file.
I am working on a university project where I have to hand in this .rmd file at the end. As a restriction, this file has to run out of the box, so unfortunately it is not an option to load the image from a given file path as I can't submit a folder containing the image or similar (and I don't want to upload it somewhere and access it via URL either).
I was looking for a way to serialize the image information and hard code it into the file but I couldn't find anything helpful related to that.
So in short, I want to do the following:
serialize image
hard code serialized image as variable in .rmd
deserialize hard coded variable and plot image data in .rmd
Is there a simple way to do this?
This seems to be unfeasible. I've tried:
image <- load.image(path)
serialized_image <- serialize(image, NULL)
some_file <- file("test", "wb")
write(serialized_image, "test")
and then I wanted to open test and copy the content manually with CTRL+C, CTRL+V into a variable in my .rmd but it turned out that the content is way too large for doing that (around 30 million lines of bytes..), so theoretically this would be a solution but unless you want a 30 million lines .rmd, this is not an option.

Why does R raster::writeRaster() generate a pic which can't be shown in Win10?

I read my hyperspectral (.raw) file and combine three bands to "gai_out_r" Then I output as following:
writeRaster(gai_out_r,filepath,format="GTiff")
finally I got gai_out_r.tif
But, why Win10 can't display this small tif as the pic that I output the same way from envi--save image as--tif
Two tiffs are displayed by Win10 as following:
Default windows image viewing applications doesn't support Hyperspectral Images-since you are just reading and combining 3 bands from your .raw file, the resulting image will be a hyperspectral image.You need to have separate dedicated softwares to view hypercubes or can view it using spectral-python also.
In sPy, using envi.save_image , will save it as a ENVI type file only. To save it as an rgb image file(readable in windows OS) we need to use other methods.
You are using writeRaster to write to a GTiff (GeoTiff) format file. To write to a standard tif file you can use the tiff method. With writeRaster you could also write to a PNG instead
writeRaster(gai_out_r, "gai.png")
Cause of the issue:
I had a similar issue and recognised that the exported .tif files had a different bit depth than .tif images I could open. The images could not be displayed using common applications, although they were not broken and I could open them in R or QGIS. Hence, the values were coded in a way Windows would not expect.
When you type ?writeRaster() you will find that there are various options when it comes to saving a .tif (or other format) using the raster::writeRaster() function. Click on the links therein to get to the dataType {raster} help site and you'll find there are various integer types to choose from.
Solution (write a Windows-readable GeoTIFF):
I set the following options to make the resulting .tif file readable (note the datatype option):
writeRaster(raster, filename = "/path/to/your/output.tif",
format = "GTiff", datatype = "INT1U")
Note:
I realised your post is from 2 and a half years ago... Anyways, may this answer help others who encounter this problem.

Generate MapTiles from BSB/KAP files Using GDAL2Tiles

As an example I have a BSB file from NOAA which is a navigational map. The map has a SRS of WGS84 and a Mercator projection.
I initially translate the file from BSB format to GTiff format using the following command:
gdal_translate -of GTiff 18554_1.kap noaa.tif
I can view this GTiff file using Paint Shop Pro quite fine. I then translate the file from GTiff format to VRT format using the following command:
gdal_translate -of vrt –expand rgba noaa.tif noaa.vrt
I then try to generate a tile matrix set using the following command:
gdal2tiles.py noaa.vrt tiles_folder
Where the map tiles are located in tiles_folder. If I try to open the openmaps.html or google.html, the map zoom in and out looks good. However, on tiles generator like MBTiles, I see tiles swap. See the image below. I am pulling my hair off to get the tiles to line up. I am guessing it is projection error. I am not understanding those projection types. It would great someone can explain it while finding the error. I am planning to use on a tiling maps/charts app like this. By the way, on GDAL how do I specify the BSB (reference) file that is associated with KAP (data) file? I have seen cases where only one BSB file referred by multiple KAP files.
Gdal2tiles swapped tiles
There is no problem with the map projection, but the tiles are cut according the TMS notation (with tile [0,0] in the bottom left) in GDAL2Tiles.
Some tools expect the Google XYZ notation (with tile [0,0] in the upper left corner).
The tiles are otherwise equal, they have just flipped Y coordinate in the file name.
Have a look at this:
I prepared a website which shows visually the difference and also explains the problem. Have a look at:
http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
There is also a source code for how the tiles and all coordinates are calculated. It is part of the GDAL2Tiles which you mentioned above - which is a code I created some years back.
Your second question is was about MBTiles. The mbutil utility has a parameter "--scheme tms" which allows to create the MBTiles file from tiles rendered with gdal2tiles.py.
GDAL reads just the KAP file, where each represents a map in the sheet (in case there are insets).
BTW Do you know that there is http://www.maptiler.com/ which solves the problems mentioned above directly? You can just drag&drop into the GUI or pass on the command line the KAP file as it is and choose whether you want tiles in directory or MBTiles and it will directly render the output. The tiles are directly optimised as well, there is support for rendering multiple input files into a single layer and rendering is of magnitude faster then with GDAL2Tiles.

Generate PDF with vector graphics

I have an idea where I need to be able to dynamically create a PDF-file thats supposed to contain a number of vector-graphical images.. I also need to be able to "absolute" position the vector images within the PDF.. I then later on need to be able to download the generated PDF-file.. is this possible?..has anyone done something like this before?.. as far as I can remember there is a pretty good support for doing this using none vectorized-images (jpg,png etc).. but is it possible to use eps-files and other vector images?
You can use pdflatex to generate the pdf.
(pdf)Latex has really good support for importing svg and eps.
When you use Inkscape you can chose to export to tex/latex and it generates code for you.

embedding a R animated 3D plot in PowerPoint

The rgl R package allows to plot interactive 3D figures and to save these figures in a html document (with the writeWebGL() function).
I would like to put such an interactive 3D figure in a PowerPoint presentation. Is it possible ?
EDIT: After studying Dieter Menne's answer with the help of Google, my conclusions are the following ones:
Currently Luke Tierney's method to convert a 3D graphic to an U3D file and/or an Asymptote file only works for graphics created with the misc3d package, not the rgl package.
The export of 3D rgl graphics to VRML/X3D files has been announced as a future plan. Perhaps this would allow to embed a 3D rgl graphic into a Powerpoint and/or LaTeX presentation.
EDIT : related discussion
It is possible if you transfer the Powerpoint presentation (or, even more R-ish, use beamer/latex), and embed the 3D-plot as described in Luke Tierney's article
http://homepage.stat.uiowa.edu/~luke/R/misc3d/misc3d-pdf/misc3d-pdf.pdf
If you put this in to an HTML document, you can probably use the IWebBrowser2 object to open the HTML inside a Slide. I am not sure how a 3d graphic would render, and I'mnot familiar with R or would not be able to offer any further advice, but you might start by trying to simply create a WebBrowser object inside your slide, and then tell it to Navigate to the HTML file.
Sub InsertHTMLFrame()
Dim sld as Slide
Dim shp as Shape
Dim wb as Object
Set sld = ActivePresentation.Slides(1) '## Modify as needed
'## Create the shape container, you will need to modify the L/T/W/H to fit your document
Set shp = sld.Shapes.AddOLEObject(100, 200, 200, 150, _
"Shell.Explorer.2")
shp.Name = "3dgraphic"
Set wb = shp.OLEFormat.Object
wb.Navigate "C:\Users\you\Desktop\exported3dgraphic.html"
End Sub
Controlling this flow during SlideShow mode may be a little trickier, but it's doable, provided the graphic renders properly through IE like this.
How to Install This Macro
Open your PowerPoint Presentation, and click Alt+F11 to bring up the Visual Basic project.
Right-click the project in the left pane, and Insert Module:
Paste the code from my answer in to this module.
In the line that says wb.Navigate "C:\..." modify this to the correct file path for your HTML file. This can be on your computer or in a shared network folder, etc.
The browser should be able to display HTML pages when in SlideShow mode, but will not render them in the normal or preview mode.

Resources