This file is indexed.

/usr/include/osmium/javascript/wrapper/geometry.hpp is in libosmium-dev 0.0~20140910-9a069af-1+b1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#ifndef OSMIUM_JAVASCRIPT_WRAPPER_GEOMETRY_HPP
#define OSMIUM_JAVASCRIPT_WRAPPER_GEOMETRY_HPP

/*

Copyright 2012 Jochen Topf <jochen@topf.org> and others (see README).

This file is part of Osmium (https://github.com/joto/osmium).

Osmium is free software: you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License or (at your option) the GNU
General Public License as published by the Free Software Foundation, either
version 3 of the Licenses, or (at your option) any later version.

Osmium is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License and the GNU
General Public License for more details.

You should have received a copy of the Licenses along with Osmium. If not, see
<http://www.gnu.org/licenses/>.

*/

#include <sstream>
#include <v8.h>

#include <geos/geom/Geometry.h>
#include <geos/geom/LineString.h>
#include <geos/geom/Polygon.h>

#include <osmium/javascript/unicode.hpp>
#include <osmium/javascript/template.hpp>
#include <osmium/javascript/wrapper/position.hpp>
#include <osmium/geometry/null.hpp>
#include <osmium/geometry/point.hpp>
#include <osmium/geometry/linestring.hpp>
#include <osmium/geometry/polygon.hpp>
#include <osmium/geometry/multipolygon.hpp>

namespace Osmium {

    namespace Javascript {

        namespace Wrapper {

            struct Geometry : public Osmium::Javascript::Template {

                static v8::Handle<v8::Value> to_wkt(const v8::Arguments& args, Osmium::Geometry::Geometry* geometry) {
                    std::ostringstream oss;
                    bool with_srid = false;
                    if (args.Length() >= 1) {
                        with_srid = args[0]->ToBoolean()->Value();
                    }
                    oss << geometry->as_WKT(with_srid);
                    return v8::String::New(oss.str().c_str());
                }

                static v8::Handle<v8::Value> to_wkb(const v8::Arguments& args, Osmium::Geometry::Geometry* geometry) {
                    std::ostringstream oss;
                    bool with_srid = false;
                    if (args.Length() >= 1) {
                        with_srid = args[0]->ToBoolean()->Value();
                    }
                    oss << geometry->as_WKB(with_srid);
                    return v8::String::New(oss.str().c_str());
                }

                static v8::Handle<v8::Value> to_hexwkb(const v8::Arguments& args, Osmium::Geometry::Geometry* geometry) {
                    std::ostringstream oss;
                    bool with_srid = false;
                    if (args.Length() >= 1) {
                        with_srid = args[0]->ToBoolean()->Value();
                    }
                    oss << geometry->as_HexWKB(with_srid);
                    return v8::String::New(oss.str().c_str());
                }

                Geometry() :
                    Osmium::Javascript::Template() {
                    js_template->Set("toWKT",    v8::FunctionTemplate::New(function_template<Osmium::Geometry::Geometry, to_wkt>));
                    js_template->Set("toWKB",    v8::FunctionTemplate::New(function_template<Osmium::Geometry::Geometry, to_wkb>));
                    js_template->Set("toHexWKB", v8::FunctionTemplate::New(function_template<Osmium::Geometry::Geometry, to_hexwkb>));
                }

            };

            struct GeometryNull : public Osmium::Javascript::Template {

                GeometryNull() :
                    Osmium::Javascript::Template() {
                    js_template->Set("toWKT",    v8::FunctionTemplate::New(undefined));
                    js_template->Set("toWKB",    v8::FunctionTemplate::New(undefined));
                    js_template->Set("toHexWKB", v8::FunctionTemplate::New(undefined));
                    js_template->Set("toArray",  v8::FunctionTemplate::New(undefined));
                }

            };

            struct GeometryPoint : public Geometry {

                static v8::Handle<v8::Value> lon(Osmium::Geometry::Point* point) {
                    return v8::Number::New(point->lon());
                }

                static v8::Handle<v8::Value> lat(Osmium::Geometry::Point* point) {
                    return v8::Number::New(point->lat());
                }

                static v8::Handle<v8::Value> to_array(const v8::Arguments& /*args*/, Osmium::Geometry::Point* point) {
                    return OSMPosition::to_array(point->position());
                }

                GeometryPoint() :
                    Geometry() {
                    js_template->SetAccessor(v8::String::NewSymbol("lon"), accessor_getter<Osmium::Geometry::Point, lon>);
                    js_template->SetAccessor(v8::String::NewSymbol("lat"), accessor_getter<Osmium::Geometry::Point, lat>);
                    js_template->Set("toArray", v8::FunctionTemplate::New(function_template<Osmium::Geometry::Point, to_array>));
                }

            };

            struct GeometryLineString : public Geometry {

                static v8::Handle<v8::Value> to_array(const v8::Arguments& /*args*/, Osmium::Geometry::LineString* ls) {
                    v8::HandleScope scope;
                    v8::Local<v8::Array> linestring = v8::Array::New(ls->nodes().size());
                    unsigned int max = ls->nodes().size() - 1;
                    const Osmium::OSM::WayNodeList& wnl = ls->nodes();
                    if (ls->reverse()) {
                        for (unsigned int i=0; i <= max; ++i) {
                            linestring->Set(max - i, OSMPosition::to_array(wnl[i].position()));
                        }
                    } else {
                        for (unsigned int i=0; i <= max; ++i) {
                            linestring->Set(i, OSMPosition::to_array(wnl[i].position()));
                        }
                    }
                    return scope.Close(linestring);
                }

                GeometryLineString() :
                    Geometry() {
                    js_template->Set("toArray", v8::FunctionTemplate::New(function_template<Osmium::Geometry::LineString, to_array>));
                }

            };

            struct GeometryPolygon : public Geometry {

                static v8::Handle<v8::Value> to_array(const v8::Arguments& /*args*/, Osmium::Geometry::Polygon* p) {
                    v8::HandleScope scope;
                    v8::Local<v8::Array> polygon = v8::Array::New(1);
                    v8::Local<v8::Array> linear_ring = v8::Array::New(p->nodes().size());
                    polygon->Set(0, linear_ring);
                    unsigned int max = p->nodes().size() - 1;
                    const Osmium::OSM::WayNodeList& wnl = p->nodes();
                    if (p->reverse()) {
                        for (unsigned int i=0; i <= max; ++i) {
                            linear_ring->Set(max - i, OSMPosition::to_array(wnl[i].position()));
                        }
                    } else {
                        for (unsigned int i=0; i <= max; ++i) {
                            linear_ring->Set(i, OSMPosition::to_array(wnl[i].position()));
                        }
                    }
                    return scope.Close(polygon);
                }

                GeometryPolygon() :
                    Geometry() {
                    js_template->Set("toArray", v8::FunctionTemplate::New(function_template<Osmium::Geometry::Polygon, to_array>));
                }

            };

            struct GeometryMultiPolygon : public Geometry {

                static v8::Handle<v8::Array> ring_as_array(const geos::geom::LineString* ring) {
                    v8::HandleScope scope;
                    const geos::geom::CoordinateSequence* cs = ring->getCoordinatesRO();
                    v8::Local<v8::Array> ring_array = v8::Array::New(cs->getSize());
                    for (size_t i = 0; i < cs->getSize(); ++i) {
                        v8::Local<v8::Array> coord = v8::Array::New(2);
                        coord->Set(0, v8::Number::New(cs->getX(i)));
                        coord->Set(1, v8::Number::New(cs->getY(i)));
                        ring_array->Set(i, coord);
                    }

                    return scope.Close(ring_array);
                }

                static v8::Handle<v8::Value> to_array(const v8::Arguments& /*args*/, Osmium::Geometry::MultiPolygon* multipolygon) {
                    v8::HandleScope scope;
                    const geos::geom::MultiPolygon* geos_multipolygon = multipolygon->borrow_geos_geometry();

                    v8::Local<v8::Array> multipolygon_array = v8::Array::New(geos_multipolygon->getNumGeometries());

                    for (size_t i=0; i < geos_multipolygon->getNumGeometries(); ++i) {
                        const geos::geom::Polygon* polygon = dynamic_cast<const geos::geom::Polygon*>(geos_multipolygon->getGeometryN(i));
                        v8::Local<v8::Array> polygon_array = v8::Array::New(polygon->getNumInteriorRing());
                        multipolygon_array->Set(i, polygon_array);
                        polygon_array->Set(0, ring_as_array(polygon->getExteriorRing()));
                        for (size_t j=0; j < polygon->getNumInteriorRing(); ++j) {
                            polygon_array->Set(j+1, ring_as_array(polygon->getInteriorRingN(j)));
                        }
                    }
                    return scope.Close(multipolygon_array);
                }

                GeometryMultiPolygon() :
                    Geometry() {
                    js_template->Set("toArray", v8::FunctionTemplate::New(function_template<Osmium::Geometry::MultiPolygon, to_array>));
                }

            };

        } // namespace Wrapper

    } // namespace Javascript

} // namespace Osmium

#endif // OSMIUM_JAVASCRIPT_WRAPPER_GEOMETRY_HPP