]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/voronoi/voronoi_main.cpp
move checkModilePresence to class, delete own debug echo
[nominatim.git] / nominatim / voronoi / voronoi_main.cpp
1 /*\r
2 * The author of this software is Shane O'Sullivan.  \r
3 * Permission to use, copy, modify, and distribute this software for any\r
4 * purpose without fee is hereby granted, provided that this entire notice\r
5 * is included in all copies of any software which is or includes a copy\r
6 * or modification of this software and in all copies of the supporting\r
7 * documentation for such software.\r
8 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED\r
9 * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY\r
10 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY\r
11 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.\r
12 */\r
13 \r
14 \r
15 #\r
16 #include <stdio.h>\r
17 #include <search.h>\r
18 #include <malloc.h>\r
19 #include "VoronoiDiagramGenerator.h"\r
20 \r
21 \r
22 \r
23 int main(int argc, char **argv) \r
24 {       \r
25         double xmin, xmax, ymin, ymax;\r
26         scanf("%lf %lf %lf %lf", &xmin, &xmax, &ymin, &ymax) ;\r
27 \r
28         SourcePoint * sites;\r
29         long nsites;\r
30 \r
31         nsites = 0;\r
32         sites = (SourcePoint *) malloc(4000 * sizeof(SourcePoint));\r
33         while (scanf("%d %lf %lf %lf", &sites[nsites].id, &sites[nsites].weight, &sites[nsites].x, &sites[nsites].y) != EOF)\r
34         {\r
35                 nsites++;\r
36                 if (nsites % 4000 == 0) {\r
37                         sites = (SourcePoint *)realloc(sites,(nsites+4000)*sizeof(SourcePoint));\r
38                 }\r
39         }\r
40 \r
41         VoronoiDiagramGenerator * pvdg;\r
42         pvdg = new VoronoiDiagramGenerator();\r
43         pvdg->generateVoronoi(sites, nsites, xmin, xmax, ymin, ymax, 0);\r
44 \r
45 //      printf("sites %ld\n-------------------------------\n", nsites);\r
46         PolygonPoint* pSitePoints;\r
47         int numpoints, i, j;\r
48         for(i = 0; i < nsites; i++)\r
49         {\r
50                 pvdg->getSitePoints(i, &numpoints, &pSitePoints);\r
51                 if (numpoints == 0)\r
52                 {\r
53                         printf("-- no points for %d\n", i);\r
54                 }\r
55                 else\r
56                 {\r
57 \r
58 \r
59                         printf("update temp_child_4076440_0 set resultgeom = st_setsrid('POLYGON((");\r
60                         for(j = 0; j < numpoints; j++)\r
61                         {\r
62                                 printf("%.15lf %.15lf,", pSitePoints[j].coord.x, pSitePoints[j].coord.y, (pSitePoints[j].angle/M_PI)*180);\r
63                         }\r
64                         printf("%.15lf %.15lf", pSitePoints[0].coord.x, pSitePoints[0].coord.y, (pSitePoints[j].angle/M_PI)*180);\r
65                         printf("))'::geometry,4326) where id = %d;\n", sites[i].id);\r
66 \r
67                 }\r
68         }\r
69 \r
70         float x1,y1,x2,y2;\r
71 //      printf("sites %ld\n-------------------------------\n", nsites);\r
72         pvdg->resetIterator();\r
73         while(pvdg->getNext(x1,y1,x2,y2))\r
74         {\r
75                 printf("(%f %f,%f %f)\n",x1,y1,x2, y2);\r
76                 \r
77         }\r
78 \r
79         delete pvdg;\r
80         free(sites);\r
81 \r
82         return 0;\r
83 }\r
84 \r
85 \r
86 \r