source: subversion/applications/rendering/gosmore/density.c @ 19932

Last change on this file since 19932 was 19893, checked in by nic, 10 years ago

Rebuild: Filter out more bulk imports
Density / bboxes: Smaller boxes, better algorithm. Replace png imagemap with OpenLayers?
Windows: Improve installer script.
Better default background

  • Property svn:executable set to *
File size: 4.4 KB
Line 
1// Run this program with :
2// gcc -Wall -lm density.c && ./a.exe <density4.txt >density.sh
3// sudo apt-get install netpbm
4// for n in *.pnm; do pnmtopng <$n >${n%.pnm}.png; done
5//
6// The input to it is a list of OO Calc expressions (sums)
7// Only the ranges are extracted. The actual calculations are ignored.
8// First it will output the osmosis command for generating the extracts
9// Then it will output a list of cells that are covered by none of the bboxes
10// (if any). It is recommended to add ranges until all cells are covered.
11// At the same time it will create and image map (density.html) and the
12// associated images.
13#include <stdio.h>
14#include <string.h>
15#include <math.h>
16
17//#include "density.xbm"
18
19#define DIM 1024
20int col[2], row[2], c, se = 0, cov[DIM][DIM], i, j, m, mat[DIM][DIM];
21int hshrink, vshrink, bcnt[2] = { 0, 0 };
22char block[2][98765], *bptr[2] = { block[0], block[1] };
23
24#define N2(x) ((x) ? (x) + 'A' - 1 : '0')
25int main (void)
26{
27  char fname[30];
28  FILE *pnm, *html, *html2, *gosm = fopen ("bboxes.c", "w");
29  memset (cov, 0, sizeof (cov));
30  memset (mat, 0, sizeof (mat));
31  html= fopen ("density.html", "w");
32  fprintf (html, "\
33<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\
34    <head>\n\
35        <title>Gosmore Map Selection</title>\n\
36        <script src=\"http://www.openlayers.org/api/OpenLayers.js\"></script>\n\
37        <script src=\"http://www.openstreetmap.org/openlayers/OpenStreetMap.js\"></script>\n\
38        <script type=\"text/javascript\">\n\
39            var box_extents = [\n");
40  while (scanf ("%d %d %d %d\n", &col[0], &row[0], &col[1], &row[1]) > 0) {
41    if (1) {
42      fprintf (gosm, "{ %d, %d, %d, %d },\n", col[0] - 512, row[0] - 512,
43        col[1] - 512, row[1] - 512);
44      sprintf (fname, "%04d%04d%04d%04d", col[0], row[0],
45               col[1], row[1]);
46      fprintf (html, "[ %10.5lf, %10.5lf, %10.5lf, %10.5lf, \"%s\" ],\n",
47              col[0] * 360.0 / DIM - 180,
48        (atan (exp ((1 - row[1] / 512.0) * M_PI)) - M_PI / 4) / M_PI * 360,
49                col[1] * 360.0 / DIM - 180,
50        (atan (exp ((1 - row[0] / 512.0) * M_PI)) - M_PI / 4) / M_PI * 360,
51              fname);
52     
53/*      hshrink = col[1] - col[0] > 60 ? 15 : (col[1] - col[0]) / 4;
54      vshrink = row[1] - row[0] > 60 ? 15 : (row[1] - row[0]) / 4;
55      for (i = row[0] + vshrink; i <= row[1] - vshrink; i++) {
56        mat[i][col[0] + hshrink] = mat[i][col[1] - hshrink] = 192;
57      }
58      for (j = col[0] + hshrink; j <= col[1] - hshrink; j++) {
59        mat[row[0] + vshrink][j] = mat[row[1] - vshrink][j] = 192;
60      }
61      fprintf (html, "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%.16s.html\" \n\
62  OnMouseOver=\"mouseover('%.16s')\" OnMouseOut=\"mouseover('map')\" />\n",
63                 col[0] + hshrink, row[0] + vshrink,
64                 col[1] - hshrink, row[1] - vshrink, fname, fname);*/
65//      printf (" --bp file=%s --wx %.16s.osm.bz2 \\\n",fname, fname);
66      bptr[col[1] > 418 ? 0 : 1] += sprintf (bptr[col[1] > 418 ? 0 : 1],
67        " \\\n --bb  idTrackerType=\"BitSet\" left=%.5lf right=%.5lf top=%.5lf bottom=%.5lf --wx %.16s.osm.gz",
68              col[0] * 360.0 / DIM - 180, col[1] * 360.0 / DIM - 180,
69        (atan (exp ((1 - row[0] / 512.0) * M_PI)) - M_PI / 4) / M_PI * 360,
70        (atan (exp ((1 - row[1] / 512.0) * M_PI)) - M_PI / 4) / M_PI * 360,
71              fname);
72      bcnt[col[1] > 418 ? 0 : 1]++;
73/*    poly = fopen (fname, "w");
74      fprintf (poly, "%.16s\n1\n", fname);
75      for (i = 0; i < 4; i++) {
76        fprintf (poly, "  %10.5lf  %10.5lf\n", col[i * (3 - i) / 2] * 360.0
77                 / DIM - 180.0,  (atan (exp ((1 - row[i / 2] / 512.0)
78                                       * M_PI)) - M_PI / 4) / M_PI * 360);
79      }
80      fprintf (poly, "END\nEND\n");
81      fclose (poly); */
82      for (i = col[0]; i < col[1]; i++) {
83        for (j = row[0]; j < row[1]; j++) cov[i][j] = 1;
84      }
85    }
86  }
87  printf ("bzcat planet-latest.osm.bz2 | ./gosmore sort Relations | \n\
88 osmosis --read-xml enableDateParsing=no file=/dev/stdin --tee %d \\\n\
89  --bb idTrackerType=\"BitSet\" left=-180 right=-33.04688\
90 top=85.05113 bottom=-90 --wx left.osm.gz%s\n\n\
91gunzip <left.osm.gz | osmosis\
92 --read-xml enableDateParsing=no file=/dev/stdin --tee %d%s\n\n",
93      bcnt[0] + 1, block[0], bcnt[1], block[1]);
94  c = 0; // The error count
95  for (i = 0; i < DIM; i++) {
96    for (j = 0; j < DIM; j++) {
97      if (!cov[i][j]) fprintf (stderr, "ERROR %d ! %c%c%c%d not coverd !\n",
98        c++, (i)/26/26+'A'-1, (i)/26%26+'A'-1, (i)%26+'A', j+1);
99    }
100  }
101  fclose (html);
102  return c;
103}
Note: See TracBrowser for help on using the repository browser.