Dynamically overlaying vector graphics on a PDF - pdf

I have a particular requirement to generate a PDF document with some dynamic data overlaid on top.
That's the general gist. To be clear, I have a fair amount of experience in generating PDFs programatically so I'm not looking for a list of products that can simply churn out PDF.
The specifics are:
I have a pre-existing PDF template containing a vector representation of certain regions of the UK. I will be capturing geographical data via a web interface and will need to overlay these data on the PDF as vector graphics (little circles with numbers to be specific).
So, what I'm looking for is some advice on:
How to dynamically write vector graphics to a PDF
Translation of geographical coordinates to vector layer coordinates
Cheers.
Steve

iText[Sharp] can handle the vector graphics portion fairly easily with a PdfStamper.
There have been several questions on the itext-questions mailing list about geographic coordinates that should help you on that front as well. Searching your favorite list archive for "geospatial" should turn them up.
I don't think we've added higher-level functions for that sort of thing yet, so you'll have to dig into PdfDictionary, PdfArray, and so forth. Keep a copy of the PDF Reference handy (but you probably already do).

Related

Programmatically check for scale information in a PDF document?

The main topic I am interested in is whether it is possible to store and extract well-structured scale information from a PDF document.
[ For example, most engineering or architectural drawings printed to a PDF would be scaled down, say 1/8 in. : 1 ft. So if actually printed to paper you could measure a part of the drawing in inches and then infer the actual real-world size in feet. ]
Is there any way to programmatically look for that scale information in the PDF format? e.g., from the example above, to extract the 1/8" : 1' ratio from the PDF.
I thought this was not even possible until I came across this statement in the Adobe document Grids, guides, and measurements in PDFs:
Use Scales And Units From Document (When Present)
When enabled, measurements based on the units generated from the
original document, if present, are used. Deselect this option to
specify the units of measurements manually.
(Alternative document with same text, p. 92)
However I can find no other references that explain how this feature works. I checked in the PDF specifications (maybe too old of a version?) and it did not mention anything. But its hard to know what to search for and I'm not very familiar with PDF internals so I may simply have missed it.
A related detail is what level of the PDF this information would be stored at (if it exists at all) - I would guess per-page?
To be clear, I am absolutely not looking to scrape text from the rendered PDF. Instead, I want to find out if there is any metadata that would encode this information. The PDFs I have to deal with would have widely varying origins & contents.
If you look at the actual PDF specification (i.e. ISO 32000, part 1 or 2), you'll find a section on measurement properties.
E.g. in ISO 32000-1:
12.9 Measurement Properties
PDF documents, such as those created by CAD software, may contain graphics that are intended to represent real-world objects. Users of such documents often require information about the scale and units of measurement of the corresponding real-world objects and their relationship to units in PDF user space.
...
Beginning with PDF 1.6, such information may be stored in a measure dictionary (see Table 261). Measure dictionaries provide information about measurement units associated with a rectangular area of the document known as a viewport.
A viewport (PDF 1.6) is a rectangular region of a page. The optional VP entry in a page dictionary (see Table 30) shall specify an array of viewport dictionaries, whose entries shall be as shown in Table 260. Viewports allow different measurement scales (specified by the Measure entry) to be used in different areas of a page, if necessary.
etc. etc.
Thus, yes, you can programmatically look for that scale information in the PDF format. Beware, though, these properties are optional, so you'll find them only if the PDF producer was nice enough to provide them.

Optimizing the Layout of Arbitrary Shapes in a Plane

I am trying to create an algorithm that can take a set of objects and organize them in a given area such that a box bounding all of the shapes is optimized (either by area used, or by maximizing the span along one of the dimensions, etc.). All of the shapes are closed and bounded.
The purpose of this is to try and minimize material waste from using a laser cutter. The shapes are generated in CAD and can read into this algorithm. The algorithm will then take arguments for the working area (effective laser cutting area) as well as the minimum separation between any two objects, then attempt to organize the objects within the specified dimensions while trying to minimize the area usage. Alternatively, the algorithm can also try to maximize the object locations along one axis while minimizing the span along the other dimension. This would be akin to cutting off a smaller workpiece to cut from.
Ideally, the algorithm would be able to make translations AND rotations, but rotations aren't necessary.
For example, this Picture depicts the required transformation.
It should work with an arbitrary, but small (<25) number of objects.
Lastly, I don't expect anyone to solve this for me, but I would appreciate help toward either finding an algorithm that can do this, or developing my own. Thank you.
I dont know to what extent you want to create said algorithm or how you want to implement it, But i know of a program called OptiNest that can do what you ask. It organizes geometric shapes to optimize the layout and minimize waste on a plane, i think in an autocad format.

What tools are commonly used to visualize meteorological and climatological data?

I am interested in visualizing meteorological and climatological data.
Here we are talking about 2D/3D visualization for weather and climate elements:
Temperature
Pressure
Wind
Example
We have used some tools previously, such as:
GrADS
Surfer (commercial software)
GIS Meteo (commercial software)
What another tools (preferably open source) would you suggest for that purpose nowadays?
I know you mentioned GrADS, but it was the tool I used mostly for development of weather products, a little more intuitive and resource friendly than IDV when I coded, and generally pretty good rate of development. You mentioned Open Source... did you know there is an OpenGrADS (http://opengrads.org/)? Most friends involved in weather product development use a combination of GrADS\OpenGrADS for much of their work. But I agree it doesn't produce knock-your-socks-off graphics.
Another commonly used free program is Gempak, another Unidata product, which really seems to be becoming outdated in my personal opinion).
And then you can talk high end graphics, you're going to pay more. http://moe.met.fsu.edu/~hrw22/movies/WIND_Katrina_2005-08-28_00Z.gif is a great video of Katrina that was produced by someone I knew using Amira. According to Wikipedia, you're looking at
"Cost: $4,000 USD + $800/year support (2009)... although now has much more ugly/complex pricing structure where each feature is priced separately (eg: Amira Mesh Option $360). I believe at NCMIR we pay ~$9000/year for five user-license." Ouch!
I don't have an open source tool, but if you can get access to a Level-II data feed (Level-II is minimally post processed radar data), I and a meteorologist friend use GR2Analyst. I would assume you know enough about weather sources to be able to figure out how to set this up.
If you're looking for an open source (and free) tool that can do 2D and 3D, which also includes access to a wide variety of datasets (obs, model output, remote sensing - radar level 2 and 3, satellite, and more!), then you might want to check out the Unidata Integrated Data Viewer (IDV):
http://www.unidata.ucar.edu/software/idv/
Source code available here:
https://github.com/Unidata/IDV
The interface is a bit complex, but we have some youtube screencasts to help people get up and going:
http://www.youtube.com/user/unidatanews/videos
If you'd like to see a video for a specific thing, we are taking requests :-) (email support-idv#unidata.ucar.edu). We do yearly training workshops as well, and those materials are available online here:
http://www.unidata.ucar.edu/software/idv/docs/workshop/
Cheers!
Sean
Panoply is a multiplataform desktop option if data is available in formats such NetCDF, HDF or GRIB.
I extracted the following text from his site that describes some of the characteristics:
Slice and plot geo-gridded latitude-longitude, latitude-vertical, longitude-vertical, or time-latitude arrays from larger multidimensional variables.
Slice and plot "generic" 2D arrays from larger multidimensional variables.
Slice 1D arrays from larger multidimensional variables and create line plots.
Combine two geo-gridded arrays in one plot by differencing, summing or averaging.
Plot lon-lat data on a global or regional map using any of over 100 map projections or make a zonal average line plot.
Overlay continent outlines or masks on lon-lat map plots.
Use any of numerous color tables for the scale colorbar, or apply your own custom ACT, CPT, or RGB color table.
Save plots to disk GIF, JPEG, PNG or TIFF bitmap images or as PDF or PostScript graphics files.
Export lon-lat map plots in KMZ format.
Export animations as AVI or MOV video or as a collection of invididual frame images.
Explore remote THREDDS and OpenDAP catalogs and open datasets served from them.
If you are interested in interactive visualization over web, there are some options such as:
ncWMS: an webmapping server that reads NetCDF data and publish it using Web Mapping Service standard.
GeoServer: another webmapping server that has plugin to read NetCDF data.
Vtk (visualization Toolkit) is a C++ open source 2D and 3D visualization library that I use to visualize radar data in 3D.

How to create a 'vector movie' out of data?

What file formats and software could I use to represent vector images over time as an animation, without compromising the advantages of the vector format?
Say I generate data that is best represented as a single point in the plane, moving over time. I would like to make an animation showing the motion of this point. One way to do this is to make a sequence of 2D bitmap images and string these together into an AVI file. But this produces either huge files (orders of magnitude larger than the underlying dataset) or very low quality animations. A stack of raster images is a very inefficient representation of the data.
A much better representation would be a sequence of 2D vector images. Vector images combine very high fidelity with small file size. But is it possible to string such images into an animation? What kind of software could be used to do so, starting from the underlying dataset?
I imagine a tool such as Adobe Flash could be used here, but this seems akin to making scatterplots from scratch in Illustrator: sure, it can be done and will look nice, but this is not how you make scatterplots. You use R, Excel or MATLAB, and then perhaps retouch the plot in a graphics program. I'm looking for a similarly efficient solution, but for making dynamic visualizations rather than plots.

iOS: Generate image from non-image data (Godus like landscape)

So upon seeing images from Godus I was wondering how to generate a simple, non-interactive, 2D image with different colors for different heights or layers of heights like on the picture below.
I was just thinking in terms of generating the basic layers of colors for the topography without the houses, trees objects and units. I wasn't thinking in terms of creating a graphics engine that would solve this, but a simple way to generate a flat image on the screen.
The question is two-fold:
1, What kind of data could be used for this sort of generation? I was thinking maybe ASCII art which is kind of easy to create and modify to quickly change the topography, but would be difficult to provide height information.
2, What existing frameworks, classes, methods or methodologies could be used for solving the generation after having the data ready.
Godus:
ASCII art (northern europe with ! for Norway, # for Sweden, $ for Finland and % for Russia:
(Taken from the MapBox docs: http://mapbox.com/developers/utfgrid/#map_data_as_ascii_art)
If you want to create a simple 2D, contoured image, I would try the following:
Create some height data. I'd just use a grey-scale image for that, rather than ascii. You can author basic height-maps in MS Paint, or anything similar.
Smooth the data. For example, apply a blur, or increase the resolution using a smooth filter.
Consider clamping all height data below a certain point - this represents a water level, if you want that.
Quantise the data. The more you quantise, the fewer but more obvious the contours.
Apply a false colouring, via a palette lookup. For example a : low lying areas blue, for water, then yellow, for sand, green for grass, brown for earth, grey for rock, and white for snow.
The important parts are the enlarging/smoothing filter, which creates more interesting shapes to your contours, and the quantisation which actually creates the contours themselves.
You can play with the stages of this. For example you could introduce some noise to the terrain, to make it look more natural if your source data is very clean. Or you could increase the smoothing if you want everything very rounded.
If you want to use ascii, you could just generate a bitmap directly from that, which wouldn't be tricky. The ascii you use as an example though is split up by country rather than terrain, so the false-colouring and contouring would probably do the wrong thing. You could probably use it as input to a simple terrain generator, perhaps just having a couple of chars to denote where you want land, sea, mountains, etc.
Here's a very basic example I knocked up, it's just an application of the technique I suggested. I didn't use any frameworks or libs, just a few simple image processing functions, and an height-map of Europe I found: