├── .gitignore
├── GPL.md
├── LGPL.md
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── output
├── berlin-restaurant-density.geojson
├── relation-122895.geojson
└── relation-16566.geojson
├── settings.gradle
└── src
└── main
├── java
└── de
│ └── topobyte
│ └── osm4j
│ └── examples
│ ├── ListRestaurantsFromOverpassInBoundingBox.java
│ ├── history
│ ├── GeofabrikUtils.java
│ ├── HistoryBasics.java
│ ├── HistoryOfRestaurants.java
│ └── HistoryVisibilityStats.java
│ ├── misc
│ └── ListRestaurantsInHavana.java
│ └── tutorial
│ ├── CountingBusinesses.java
│ ├── CountingElements.java
│ ├── CountingElements2.java
│ ├── CountingElements3.java
│ ├── HelloWorld.java
│ ├── MapRendering.java
│ ├── OverpassToPbf.java
│ ├── PbfToXml.java
│ └── geometry
│ ├── BouroughBboxesBerlin.java
│ ├── BuildPolygon1.java
│ ├── BuildPolygon2.java
│ ├── BuildWayPolygon.java
│ ├── GeoJsonHelper.java
│ ├── PolygonBufferDifference.java
│ ├── PolygonBufferNegative.java
│ ├── PolygonBufferPositive.java
│ └── RestaurantDensityBerlin.java
└── resources
└── log4j.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | build
3 | .gradle
4 | .project
5 | .classpath
6 | .settings
7 | *.swp
8 | src/main/resources/secure.properties
9 |
--------------------------------------------------------------------------------
/GPL.md:
--------------------------------------------------------------------------------
1 | GNU General Public License
2 | ==========================
3 |
4 | _Version 3, 29 June 2007_
5 | _Copyright © 2007 Free Software Foundation, Inc. <>_
6 |
7 | Everyone is permitted to copy and distribute verbatim copies of this license
8 | document, but changing it is not allowed.
9 |
10 | ## Preamble
11 |
12 | The GNU General Public License is a free, copyleft license for software and other
13 | kinds of works.
14 |
15 | The licenses for most software and other practical works are designed to take away
16 | your freedom to share and change the works. By contrast, the GNU General Public
17 | License is intended to guarantee your freedom to share and change all versions of a
18 | program--to make sure it remains free software for all its users. We, the Free
19 | Software Foundation, use the GNU General Public License for most of our software; it
20 | applies also to any other work released this way by its authors. You can apply it to
21 | your programs, too.
22 |
23 | When we speak of free software, we are referring to freedom, not price. Our General
24 | Public Licenses are designed to make sure that you have the freedom to distribute
25 | copies of free software (and charge for them if you wish), that you receive source
26 | code or can get it if you want it, that you can change the software or use pieces of
27 | it in new free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you these rights or
30 | asking you to surrender the rights. Therefore, you have certain responsibilities if
31 | you distribute copies of the software, or if you modify it: responsibilities to
32 | respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether gratis or for a fee,
35 | you must pass on to the recipients the same freedoms that you received. You must make
36 | sure that they, too, receive or can get the source code. And you must show them these
37 | terms so they know their rights.
38 |
39 | Developers that use the GNU GPL protect your rights with two steps: **(1)** assert
40 | copyright on the software, and **(2)** offer you this License giving you legal permission
41 | to copy, distribute and/or modify it.
42 |
43 | For the developers' and authors' protection, the GPL clearly explains that there is
44 | no warranty for this free software. For both users' and authors' sake, the GPL
45 | requires that modified versions be marked as changed, so that their problems will not
46 | be attributed erroneously to authors of previous versions.
47 |
48 | Some devices are designed to deny users access to install or run modified versions of
49 | the software inside them, although the manufacturer can do so. This is fundamentally
50 | incompatible with the aim of protecting users' freedom to change the software. The
51 | systematic pattern of such abuse occurs in the area of products for individuals to
52 | use, which is precisely where it is most unacceptable. Therefore, we have designed
53 | this version of the GPL to prohibit the practice for those products. If such problems
54 | arise substantially in other domains, we stand ready to extend this provision to
55 | those domains in future versions of the GPL, as needed to protect the freedom of
56 | users.
57 |
58 | Finally, every program is threatened constantly by software patents. States should
59 | not allow patents to restrict development and use of software on general-purpose
60 | computers, but in those that do, we wish to avoid the special danger that patents
61 | applied to a free program could make it effectively proprietary. To prevent this, the
62 | GPL assures that patents cannot be used to render the program non-free.
63 |
64 | The precise terms and conditions for copying, distribution and modification follow.
65 |
66 | ## TERMS AND CONDITIONS
67 |
68 | ### 0. Definitions
69 |
70 | “This License” refers to version 3 of the GNU General Public License.
71 |
72 | “Copyright” also means copyright-like laws that apply to other kinds of
73 | works, such as semiconductor masks.
74 |
75 | “The Program” refers to any copyrightable work licensed under this
76 | License. Each licensee is addressed as “you”. “Licensees” and
77 | “recipients” may be individuals or organizations.
78 |
79 | To “modify” a work means to copy from or adapt all or part of the work in
80 | a fashion requiring copyright permission, other than the making of an exact copy. The
81 | resulting work is called a “modified version” of the earlier work or a
82 | work “based on” the earlier work.
83 |
84 | A “covered work” means either the unmodified Program or a work based on
85 | the Program.
86 |
87 | To “propagate” a work means to do anything with it that, without
88 | permission, would make you directly or secondarily liable for infringement under
89 | applicable copyright law, except executing it on a computer or modifying a private
90 | copy. Propagation includes copying, distribution (with or without modification),
91 | making available to the public, and in some countries other activities as well.
92 |
93 | To “convey” a work means any kind of propagation that enables other
94 | parties to make or receive copies. Mere interaction with a user through a computer
95 | network, with no transfer of a copy, is not conveying.
96 |
97 | An interactive user interface displays “Appropriate Legal Notices” to the
98 | extent that it includes a convenient and prominently visible feature that **(1)**
99 | displays an appropriate copyright notice, and **(2)** tells the user that there is no
100 | warranty for the work (except to the extent that warranties are provided), that
101 | licensees may convey the work under this License, and how to view a copy of this
102 | License. If the interface presents a list of user commands or options, such as a
103 | menu, a prominent item in the list meets this criterion.
104 |
105 | ### 1. Source Code
106 |
107 | The “source code” for a work means the preferred form of the work for
108 | making modifications to it. “Object code” means any non-source form of a
109 | work.
110 |
111 | A “Standard Interface” means an interface that either is an official
112 | standard defined by a recognized standards body, or, in the case of interfaces
113 | specified for a particular programming language, one that is widely used among
114 | developers working in that language.
115 |
116 | The “System Libraries” of an executable work include anything, other than
117 | the work as a whole, that **(a)** is included in the normal form of packaging a Major
118 | Component, but which is not part of that Major Component, and **(b)** serves only to
119 | enable use of the work with that Major Component, or to implement a Standard
120 | Interface for which an implementation is available to the public in source code form.
121 | A “Major Component”, in this context, means a major essential component
122 | (kernel, window system, and so on) of the specific operating system (if any) on which
123 | the executable work runs, or a compiler used to produce the work, or an object code
124 | interpreter used to run it.
125 |
126 | The “Corresponding Source” for a work in object code form means all the
127 | source code needed to generate, install, and (for an executable work) run the object
128 | code and to modify the work, including scripts to control those activities. However,
129 | it does not include the work's System Libraries, or general-purpose tools or
130 | generally available free programs which are used unmodified in performing those
131 | activities but which are not part of the work. For example, Corresponding Source
132 | includes interface definition files associated with source files for the work, and
133 | the source code for shared libraries and dynamically linked subprograms that the work
134 | is specifically designed to require, such as by intimate data communication or
135 | control flow between those subprograms and other parts of the work.
136 |
137 | The Corresponding Source need not include anything that users can regenerate
138 | automatically from other parts of the Corresponding Source.
139 |
140 | The Corresponding Source for a work in source code form is that same work.
141 |
142 | ### 2. Basic Permissions
143 |
144 | All rights granted under this License are granted for the term of copyright on the
145 | Program, and are irrevocable provided the stated conditions are met. This License
146 | explicitly affirms your unlimited permission to run the unmodified Program. The
147 | output from running a covered work is covered by this License only if the output,
148 | given its content, constitutes a covered work. This License acknowledges your rights
149 | of fair use or other equivalent, as provided by copyright law.
150 |
151 | You may make, run and propagate covered works that you do not convey, without
152 | conditions so long as your license otherwise remains in force. You may convey covered
153 | works to others for the sole purpose of having them make modifications exclusively
154 | for you, or provide you with facilities for running those works, provided that you
155 | comply with the terms of this License in conveying all material for which you do not
156 | control copyright. Those thus making or running the covered works for you must do so
157 | exclusively on your behalf, under your direction and control, on terms that prohibit
158 | them from making any copies of your copyrighted material outside their relationship
159 | with you.
160 |
161 | Conveying under any other circumstances is permitted solely under the conditions
162 | stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
163 |
164 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law
165 |
166 | No covered work shall be deemed part of an effective technological measure under any
167 | applicable law fulfilling obligations under article 11 of the WIPO copyright treaty
168 | adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention
169 | of such measures.
170 |
171 | When you convey a covered work, you waive any legal power to forbid circumvention of
172 | technological measures to the extent such circumvention is effected by exercising
173 | rights under this License with respect to the covered work, and you disclaim any
174 | intention to limit operation or modification of the work as a means of enforcing,
175 | against the work's users, your or third parties' legal rights to forbid circumvention
176 | of technological measures.
177 |
178 | ### 4. Conveying Verbatim Copies
179 |
180 | You may convey verbatim copies of the Program's source code as you receive it, in any
181 | medium, provided that you conspicuously and appropriately publish on each copy an
182 | appropriate copyright notice; keep intact all notices stating that this License and
183 | any non-permissive terms added in accord with section 7 apply to the code; keep
184 | intact all notices of the absence of any warranty; and give all recipients a copy of
185 | this License along with the Program.
186 |
187 | You may charge any price or no price for each copy that you convey, and you may offer
188 | support or warranty protection for a fee.
189 |
190 | ### 5. Conveying Modified Source Versions
191 |
192 | You may convey a work based on the Program, or the modifications to produce it from
193 | the Program, in the form of source code under the terms of section 4, provided that
194 | you also meet all of these conditions:
195 |
196 | * **a)** The work must carry prominent notices stating that you modified it, and giving a
197 | relevant date.
198 | * **b)** The work must carry prominent notices stating that it is released under this
199 | License and any conditions added under section 7. This requirement modifies the
200 | requirement in section 4 to “keep intact all notices”.
201 | * **c)** You must license the entire work, as a whole, under this License to anyone who
202 | comes into possession of a copy. This License will therefore apply, along with any
203 | applicable section 7 additional terms, to the whole of the work, and all its parts,
204 | regardless of how they are packaged. This License gives no permission to license the
205 | work in any other way, but it does not invalidate such permission if you have
206 | separately received it.
207 | * **d)** If the work has interactive user interfaces, each must display Appropriate Legal
208 | Notices; however, if the Program has interactive interfaces that do not display
209 | Appropriate Legal Notices, your work need not make them do so.
210 |
211 | A compilation of a covered work with other separate and independent works, which are
212 | not by their nature extensions of the covered work, and which are not combined with
213 | it such as to form a larger program, in or on a volume of a storage or distribution
214 | medium, is called an “aggregate” if the compilation and its resulting
215 | copyright are not used to limit the access or legal rights of the compilation's users
216 | beyond what the individual works permit. Inclusion of a covered work in an aggregate
217 | does not cause this License to apply to the other parts of the aggregate.
218 |
219 | ### 6. Conveying Non-Source Forms
220 |
221 | You may convey a covered work in object code form under the terms of sections 4 and
222 | 5, provided that you also convey the machine-readable Corresponding Source under the
223 | terms of this License, in one of these ways:
224 |
225 | * **a)** Convey the object code in, or embodied in, a physical product (including a
226 | physical distribution medium), accompanied by the Corresponding Source fixed on a
227 | durable physical medium customarily used for software interchange.
228 | * **b)** Convey the object code in, or embodied in, a physical product (including a
229 | physical distribution medium), accompanied by a written offer, valid for at least
230 | three years and valid for as long as you offer spare parts or customer support for
231 | that product model, to give anyone who possesses the object code either **(1)** a copy of
232 | the Corresponding Source for all the software in the product that is covered by this
233 | License, on a durable physical medium customarily used for software interchange, for
234 | a price no more than your reasonable cost of physically performing this conveying of
235 | source, or **(2)** access to copy the Corresponding Source from a network server at no
236 | charge.
237 | * **c)** Convey individual copies of the object code with a copy of the written offer to
238 | provide the Corresponding Source. This alternative is allowed only occasionally and
239 | noncommercially, and only if you received the object code with such an offer, in
240 | accord with subsection 6b.
241 | * **d)** Convey the object code by offering access from a designated place (gratis or for
242 | a charge), and offer equivalent access to the Corresponding Source in the same way
243 | through the same place at no further charge. You need not require recipients to copy
244 | the Corresponding Source along with the object code. If the place to copy the object
245 | code is a network server, the Corresponding Source may be on a different server
246 | (operated by you or a third party) that supports equivalent copying facilities,
247 | provided you maintain clear directions next to the object code saying where to find
248 | the Corresponding Source. Regardless of what server hosts the Corresponding Source,
249 | you remain obligated to ensure that it is available for as long as needed to satisfy
250 | these requirements.
251 | * **e)** Convey the object code using peer-to-peer transmission, provided you inform
252 | other peers where the object code and Corresponding Source of the work are being
253 | offered to the general public at no charge under subsection 6d.
254 |
255 | A separable portion of the object code, whose source code is excluded from the
256 | Corresponding Source as a System Library, need not be included in conveying the
257 | object code work.
258 |
259 | A “User Product” is either **(1)** a “consumer product”, which
260 | means any tangible personal property which is normally used for personal, family, or
261 | household purposes, or **(2)** anything designed or sold for incorporation into a
262 | dwelling. In determining whether a product is a consumer product, doubtful cases
263 | shall be resolved in favor of coverage. For a particular product received by a
264 | particular user, “normally used” refers to a typical or common use of
265 | that class of product, regardless of the status of the particular user or of the way
266 | in which the particular user actually uses, or expects or is expected to use, the
267 | product. A product is a consumer product regardless of whether the product has
268 | substantial commercial, industrial or non-consumer uses, unless such uses represent
269 | the only significant mode of use of the product.
270 |
271 | “Installation Information” for a User Product means any methods,
272 | procedures, authorization keys, or other information required to install and execute
273 | modified versions of a covered work in that User Product from a modified version of
274 | its Corresponding Source. The information must suffice to ensure that the continued
275 | functioning of the modified object code is in no case prevented or interfered with
276 | solely because modification has been made.
277 |
278 | If you convey an object code work under this section in, or with, or specifically for
279 | use in, a User Product, and the conveying occurs as part of a transaction in which
280 | the right of possession and use of the User Product is transferred to the recipient
281 | in perpetuity or for a fixed term (regardless of how the transaction is
282 | characterized), the Corresponding Source conveyed under this section must be
283 | accompanied by the Installation Information. But this requirement does not apply if
284 | neither you nor any third party retains the ability to install modified object code
285 | on the User Product (for example, the work has been installed in ROM).
286 |
287 | The requirement to provide Installation Information does not include a requirement to
288 | continue to provide support service, warranty, or updates for a work that has been
289 | modified or installed by the recipient, or for the User Product in which it has been
290 | modified or installed. Access to a network may be denied when the modification itself
291 | materially and adversely affects the operation of the network or violates the rules
292 | and protocols for communication across the network.
293 |
294 | Corresponding Source conveyed, and Installation Information provided, in accord with
295 | this section must be in a format that is publicly documented (and with an
296 | implementation available to the public in source code form), and must require no
297 | special password or key for unpacking, reading or copying.
298 |
299 | ### 7. Additional Terms
300 |
301 | “Additional permissions” are terms that supplement the terms of this
302 | License by making exceptions from one or more of its conditions. Additional
303 | permissions that are applicable to the entire Program shall be treated as though they
304 | were included in this License, to the extent that they are valid under applicable
305 | law. If additional permissions apply only to part of the Program, that part may be
306 | used separately under those permissions, but the entire Program remains governed by
307 | this License without regard to the additional permissions.
308 |
309 | When you convey a copy of a covered work, you may at your option remove any
310 | additional permissions from that copy, or from any part of it. (Additional
311 | permissions may be written to require their own removal in certain cases when you
312 | modify the work.) You may place additional permissions on material, added by you to a
313 | covered work, for which you have or can give appropriate copyright permission.
314 |
315 | Notwithstanding any other provision of this License, for material you add to a
316 | covered work, you may (if authorized by the copyright holders of that material)
317 | supplement the terms of this License with terms:
318 |
319 | * **a)** Disclaiming warranty or limiting liability differently from the terms of
320 | sections 15 and 16 of this License; or
321 | * **b)** Requiring preservation of specified reasonable legal notices or author
322 | attributions in that material or in the Appropriate Legal Notices displayed by works
323 | containing it; or
324 | * **c)** Prohibiting misrepresentation of the origin of that material, or requiring that
325 | modified versions of such material be marked in reasonable ways as different from the
326 | original version; or
327 | * **d)** Limiting the use for publicity purposes of names of licensors or authors of the
328 | material; or
329 | * **e)** Declining to grant rights under trademark law for use of some trade names,
330 | trademarks, or service marks; or
331 | * **f)** Requiring indemnification of licensors and authors of that material by anyone
332 | who conveys the material (or modified versions of it) with contractual assumptions of
333 | liability to the recipient, for any liability that these contractual assumptions
334 | directly impose on those licensors and authors.
335 |
336 | All other non-permissive additional terms are considered “further
337 | restrictions” within the meaning of section 10. If the Program as you received
338 | it, or any part of it, contains a notice stating that it is governed by this License
339 | along with a term that is a further restriction, you may remove that term. If a
340 | license document contains a further restriction but permits relicensing or conveying
341 | under this License, you may add to a covered work material governed by the terms of
342 | that license document, provided that the further restriction does not survive such
343 | relicensing or conveying.
344 |
345 | If you add terms to a covered work in accord with this section, you must place, in
346 | the relevant source files, a statement of the additional terms that apply to those
347 | files, or a notice indicating where to find the applicable terms.
348 |
349 | Additional terms, permissive or non-permissive, may be stated in the form of a
350 | separately written license, or stated as exceptions; the above requirements apply
351 | either way.
352 |
353 | ### 8. Termination
354 |
355 | You may not propagate or modify a covered work except as expressly provided under
356 | this License. Any attempt otherwise to propagate or modify it is void, and will
357 | automatically terminate your rights under this License (including any patent licenses
358 | granted under the third paragraph of section 11).
359 |
360 | However, if you cease all violation of this License, then your license from a
361 | particular copyright holder is reinstated **(a)** provisionally, unless and until the
362 | copyright holder explicitly and finally terminates your license, and **(b)** permanently,
363 | if the copyright holder fails to notify you of the violation by some reasonable means
364 | prior to 60 days after the cessation.
365 |
366 | Moreover, your license from a particular copyright holder is reinstated permanently
367 | if the copyright holder notifies you of the violation by some reasonable means, this
368 | is the first time you have received notice of violation of this License (for any
369 | work) from that copyright holder, and you cure the violation prior to 30 days after
370 | your receipt of the notice.
371 |
372 | Termination of your rights under this section does not terminate the licenses of
373 | parties who have received copies or rights from you under this License. If your
374 | rights have been terminated and not permanently reinstated, you do not qualify to
375 | receive new licenses for the same material under section 10.
376 |
377 | ### 9. Acceptance Not Required for Having Copies
378 |
379 | You are not required to accept this License in order to receive or run a copy of the
380 | Program. Ancillary propagation of a covered work occurring solely as a consequence of
381 | using peer-to-peer transmission to receive a copy likewise does not require
382 | acceptance. However, nothing other than this License grants you permission to
383 | propagate or modify any covered work. These actions infringe copyright if you do not
384 | accept this License. Therefore, by modifying or propagating a covered work, you
385 | indicate your acceptance of this License to do so.
386 |
387 | ### 10. Automatic Licensing of Downstream Recipients
388 |
389 | Each time you convey a covered work, the recipient automatically receives a license
390 | from the original licensors, to run, modify and propagate that work, subject to this
391 | License. You are not responsible for enforcing compliance by third parties with this
392 | License.
393 |
394 | An “entity transaction” is a transaction transferring control of an
395 | organization, or substantially all assets of one, or subdividing an organization, or
396 | merging organizations. If propagation of a covered work results from an entity
397 | transaction, each party to that transaction who receives a copy of the work also
398 | receives whatever licenses to the work the party's predecessor in interest had or
399 | could give under the previous paragraph, plus a right to possession of the
400 | Corresponding Source of the work from the predecessor in interest, if the predecessor
401 | has it or can get it with reasonable efforts.
402 |
403 | You may not impose any further restrictions on the exercise of the rights granted or
404 | affirmed under this License. For example, you may not impose a license fee, royalty,
405 | or other charge for exercise of rights granted under this License, and you may not
406 | initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging
407 | that any patent claim is infringed by making, using, selling, offering for sale, or
408 | importing the Program or any portion of it.
409 |
410 | ### 11. Patents
411 |
412 | A “contributor” is a copyright holder who authorizes use under this
413 | License of the Program or a work on which the Program is based. The work thus
414 | licensed is called the contributor's “contributor version”.
415 |
416 | A contributor's “essential patent claims” are all patent claims owned or
417 | controlled by the contributor, whether already acquired or hereafter acquired, that
418 | would be infringed by some manner, permitted by this License, of making, using, or
419 | selling its contributor version, but do not include claims that would be infringed
420 | only as a consequence of further modification of the contributor version. For
421 | purposes of this definition, “control” includes the right to grant patent
422 | sublicenses in a manner consistent with the requirements of this License.
423 |
424 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license
425 | under the contributor's essential patent claims, to make, use, sell, offer for sale,
426 | import and otherwise run, modify and propagate the contents of its contributor
427 | version.
428 |
429 | In the following three paragraphs, a “patent license” is any express
430 | agreement or commitment, however denominated, not to enforce a patent (such as an
431 | express permission to practice a patent or covenant not to sue for patent
432 | infringement). To “grant” such a patent license to a party means to make
433 | such an agreement or commitment not to enforce a patent against the party.
434 |
435 | If you convey a covered work, knowingly relying on a patent license, and the
436 | Corresponding Source of the work is not available for anyone to copy, free of charge
437 | and under the terms of this License, through a publicly available network server or
438 | other readily accessible means, then you must either **(1)** cause the Corresponding
439 | Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the
440 | patent license for this particular work, or **(3)** arrange, in a manner consistent with
441 | the requirements of this License, to extend the patent license to downstream
442 | recipients. “Knowingly relying” means you have actual knowledge that, but
443 | for the patent license, your conveying the covered work in a country, or your
444 | recipient's use of the covered work in a country, would infringe one or more
445 | identifiable patents in that country that you have reason to believe are valid.
446 |
447 | If, pursuant to or in connection with a single transaction or arrangement, you
448 | convey, or propagate by procuring conveyance of, a covered work, and grant a patent
449 | license to some of the parties receiving the covered work authorizing them to use,
450 | propagate, modify or convey a specific copy of the covered work, then the patent
451 | license you grant is automatically extended to all recipients of the covered work and
452 | works based on it.
453 |
454 | A patent license is “discriminatory” if it does not include within the
455 | scope of its coverage, prohibits the exercise of, or is conditioned on the
456 | non-exercise of one or more of the rights that are specifically granted under this
457 | License. You may not convey a covered work if you are a party to an arrangement with
458 | a third party that is in the business of distributing software, under which you make
459 | payment to the third party based on the extent of your activity of conveying the
460 | work, and under which the third party grants, to any of the parties who would receive
461 | the covered work from you, a discriminatory patent license **(a)** in connection with
462 | copies of the covered work conveyed by you (or copies made from those copies), or **(b)**
463 | primarily for and in connection with specific products or compilations that contain
464 | the covered work, unless you entered into that arrangement, or that patent license
465 | was granted, prior to 28 March 2007.
466 |
467 | Nothing in this License shall be construed as excluding or limiting any implied
468 | license or other defenses to infringement that may otherwise be available to you
469 | under applicable patent law.
470 |
471 | ### 12. No Surrender of Others' Freedom
472 |
473 | If conditions are imposed on you (whether by court order, agreement or otherwise)
474 | that contradict the conditions of this License, they do not excuse you from the
475 | conditions of this License. If you cannot convey a covered work so as to satisfy
476 | simultaneously your obligations under this License and any other pertinent
477 | obligations, then as a consequence you may not convey it at all. For example, if you
478 | agree to terms that obligate you to collect a royalty for further conveying from
479 | those to whom you convey the Program, the only way you could satisfy both those terms
480 | and this License would be to refrain entirely from conveying the Program.
481 |
482 | ### 13. Use with the GNU Affero General Public License
483 |
484 | Notwithstanding any other provision of this License, you have permission to link or
485 | combine any covered work with a work licensed under version 3 of the GNU Affero
486 | General Public License into a single combined work, and to convey the resulting work.
487 | The terms of this License will continue to apply to the part which is the covered
488 | work, but the special requirements of the GNU Affero General Public License, section
489 | 13, concerning interaction through a network will apply to the combination as such.
490 |
491 | ### 14. Revised Versions of this License
492 |
493 | The Free Software Foundation may publish revised and/or new versions of the GNU
494 | General Public License from time to time. Such new versions will be similar in spirit
495 | to the present version, but may differ in detail to address new problems or concerns.
496 |
497 | Each version is given a distinguishing version number. If the Program specifies that
498 | a certain numbered version of the GNU General Public License “or any later
499 | version” applies to it, you have the option of following the terms and
500 | conditions either of that numbered version or of any later version published by the
501 | Free Software Foundation. If the Program does not specify a version number of the GNU
502 | General Public License, you may choose any version ever published by the Free
503 | Software Foundation.
504 |
505 | If the Program specifies that a proxy can decide which future versions of the GNU
506 | General Public License can be used, that proxy's public statement of acceptance of a
507 | version permanently authorizes you to choose that version for the Program.
508 |
509 | Later license versions may give you additional or different permissions. However, no
510 | additional obligations are imposed on any author or copyright holder as a result of
511 | your choosing to follow a later version.
512 |
513 | ### 15. Disclaimer of Warranty
514 |
515 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
516 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
517 | PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
518 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
519 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
520 | QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
521 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
522 |
523 | ### 16. Limitation of Liability
524 |
525 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
526 | COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS
527 | PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
528 | INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
529 | PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE
530 | OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
531 | WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
532 | POSSIBILITY OF SUCH DAMAGES.
533 |
534 | ### 17. Interpretation of Sections 15 and 16
535 |
536 | If the disclaimer of warranty and limitation of liability provided above cannot be
537 | given local legal effect according to their terms, reviewing courts shall apply local
538 | law that most closely approximates an absolute waiver of all civil liability in
539 | connection with the Program, unless a warranty or assumption of liability accompanies
540 | a copy of the Program in return for a fee.
541 |
542 | _END OF TERMS AND CONDITIONS_
543 |
544 | ## How to Apply These Terms to Your New Programs
545 |
546 | If you develop a new program, and you want it to be of the greatest possible use to
547 | the public, the best way to achieve this is to make it free software which everyone
548 | can redistribute and change under these terms.
549 |
550 | To do so, attach the following notices to the program. It is safest to attach them
551 | to the start of each source file to most effectively state the exclusion of warranty;
552 | and each file should have at least the “copyright” line and a pointer to
553 | where the full notice is found.
554 |
555 |
556 | Copyright (C)
557 |
558 | This program is free software: you can redistribute it and/or modify
559 | it under the terms of the GNU General Public License as published by
560 | the Free Software Foundation, either version 3 of the License, or
561 | (at your option) any later version.
562 |
563 | This program is distributed in the hope that it will be useful,
564 | but WITHOUT ANY WARRANTY; without even the implied warranty of
565 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
566 | GNU General Public License for more details.
567 |
568 | You should have received a copy of the GNU General Public License
569 | along with this program. If not, see .
570 |
571 | Also add information on how to contact you by electronic and paper mail.
572 |
573 | If the program does terminal interaction, make it output a short notice like this
574 | when it starts in an interactive mode:
575 |
576 | Copyright (C)
577 | This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
578 | This is free software, and you are welcome to redistribute it
579 | under certain conditions; type 'show c' for details.
580 |
581 | The hypothetical commands `show w` and `show c` should show the appropriate parts of
582 | the General Public License. Of course, your program's commands might be different;
583 | for a GUI interface, you would use an “about box”.
584 |
585 | You should also get your employer (if you work as a programmer) or school, if any, to
586 | sign a “copyright disclaimer” for the program, if necessary. For more
587 | information on this, and how to apply and follow the GNU GPL, see
588 | <>.
589 |
590 | The GNU General Public License does not permit incorporating your program into
591 | proprietary programs. If your program is a subroutine library, you may consider it
592 | more useful to permit linking proprietary applications with the library. If this is
593 | what you want to do, use the GNU Lesser General Public License instead of this
594 | License. But first, please read
595 | <>.
596 |
--------------------------------------------------------------------------------
/LGPL.md:
--------------------------------------------------------------------------------
1 | GNU Lesser General Public License
2 | =================================
3 |
4 | _Version 3, 29 June 2007_
5 | _Copyright © 2007 Free Software Foundation, Inc. <>_
6 |
7 | Everyone is permitted to copy and distribute verbatim copies
8 | of this license document, but changing it is not allowed.
9 |
10 |
11 | This version of the GNU Lesser General Public License incorporates
12 | the terms and conditions of version 3 of the GNU General Public
13 | License, supplemented by the additional permissions listed below.
14 |
15 | ### 0. Additional Definitions
16 |
17 | As used herein, “this License” refers to version 3 of the GNU Lesser
18 | General Public License, and the “GNU GPL” refers to version 3 of the GNU
19 | General Public License.
20 |
21 | “The Library” refers to a covered work governed by this License,
22 | other than an Application or a Combined Work as defined below.
23 |
24 | An “Application” is any work that makes use of an interface provided
25 | by the Library, but which is not otherwise based on the Library.
26 | Defining a subclass of a class defined by the Library is deemed a mode
27 | of using an interface provided by the Library.
28 |
29 | A “Combined Work” is a work produced by combining or linking an
30 | Application with the Library. The particular version of the Library
31 | with which the Combined Work was made is also called the “Linked
32 | Version”.
33 |
34 | The “Minimal Corresponding Source” for a Combined Work means the
35 | Corresponding Source for the Combined Work, excluding any source code
36 | for portions of the Combined Work that, considered in isolation, are
37 | based on the Application, and not on the Linked Version.
38 |
39 | The “Corresponding Application Code” for a Combined Work means the
40 | object code and/or source code for the Application, including any data
41 | and utility programs needed for reproducing the Combined Work from the
42 | Application, but excluding the System Libraries of the Combined Work.
43 |
44 | ### 1. Exception to Section 3 of the GNU GPL
45 |
46 | You may convey a covered work under sections 3 and 4 of this License
47 | without being bound by section 3 of the GNU GPL.
48 |
49 | ### 2. Conveying Modified Versions
50 |
51 | If you modify a copy of the Library, and, in your modifications, a
52 | facility refers to a function or data to be supplied by an Application
53 | that uses the facility (other than as an argument passed when the
54 | facility is invoked), then you may convey a copy of the modified
55 | version:
56 |
57 | * **a)** under this License, provided that you make a good faith effort to
58 | ensure that, in the event an Application does not supply the
59 | function or data, the facility still operates, and performs
60 | whatever part of its purpose remains meaningful, or
61 |
62 | * **b)** under the GNU GPL, with none of the additional permissions of
63 | this License applicable to that copy.
64 |
65 | ### 3. Object Code Incorporating Material from Library Header Files
66 |
67 | The object code form of an Application may incorporate material from
68 | a header file that is part of the Library. You may convey such object
69 | code under terms of your choice, provided that, if the incorporated
70 | material is not limited to numerical parameters, data structure
71 | layouts and accessors, or small macros, inline functions and templates
72 | (ten or fewer lines in length), you do both of the following:
73 |
74 | * **a)** Give prominent notice with each copy of the object code that the
75 | Library is used in it and that the Library and its use are
76 | covered by this License.
77 | * **b)** Accompany the object code with a copy of the GNU GPL and this license
78 | document.
79 |
80 | ### 4. Combined Works
81 |
82 | You may convey a Combined Work under terms of your choice that,
83 | taken together, effectively do not restrict modification of the
84 | portions of the Library contained in the Combined Work and reverse
85 | engineering for debugging such modifications, if you also do each of
86 | the following:
87 |
88 | * **a)** Give prominent notice with each copy of the Combined Work that
89 | the Library is used in it and that the Library and its use are
90 | covered by this License.
91 |
92 | * **b)** Accompany the Combined Work with a copy of the GNU GPL and this license
93 | document.
94 |
95 | * **c)** For a Combined Work that displays copyright notices during
96 | execution, include the copyright notice for the Library among
97 | these notices, as well as a reference directing the user to the
98 | copies of the GNU GPL and this license document.
99 |
100 | * **d)** Do one of the following:
101 | - **0)** Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 | - **1)** Use a suitable shared library mechanism for linking with the
109 | Library. A suitable mechanism is one that **(a)** uses at run time
110 | a copy of the Library already present on the user's computer
111 | system, and **(b)** will operate properly with a modified version
112 | of the Library that is interface-compatible with the Linked
113 | Version.
114 |
115 | * **e)** Provide Installation Information, but only if you would otherwise
116 | be required to provide such information under section 6 of the
117 | GNU GPL, and only to the extent that such information is
118 | necessary to install and execute a modified version of the
119 | Combined Work produced by recombining or relinking the
120 | Application with a modified version of the Linked Version. (If
121 | you use option **4d0**, the Installation Information must accompany
122 | the Minimal Corresponding Source and Corresponding Application
123 | Code. If you use option **4d1**, you must provide the Installation
124 | Information in the manner specified by section 6 of the GNU GPL
125 | for conveying Corresponding Source.)
126 |
127 | ### 5. Combined Libraries
128 |
129 | You may place library facilities that are a work based on the
130 | Library side by side in a single library together with other library
131 | facilities that are not Applications and are not covered by this
132 | License, and convey such a combined library under terms of your
133 | choice, if you do both of the following:
134 |
135 | * **a)** Accompany the combined library with a copy of the same work based
136 | on the Library, uncombined with any other library facilities,
137 | conveyed under the terms of this License.
138 | * **b)** Give prominent notice with the combined library that part of it
139 | is a work based on the Library, and explaining where to find the
140 | accompanying uncombined form of the same work.
141 |
142 | ### 6. Revised Versions of the GNU Lesser General Public License
143 |
144 | The Free Software Foundation may publish revised and/or new versions
145 | of the GNU Lesser General Public License from time to time. Such new
146 | versions will be similar in spirit to the present version, but may
147 | differ in detail to address new problems or concerns.
148 |
149 | Each version is given a distinguishing version number. If the
150 | Library as you received it specifies that a certain numbered version
151 | of the GNU Lesser General Public License “or any later version”
152 | applies to it, you have the option of following the terms and
153 | conditions either of that published version or of any later version
154 | published by the Free Software Foundation. If the Library as you
155 | received it does not specify a version number of the GNU Lesser
156 | General Public License, you may choose any version of the GNU Lesser
157 | General Public License ever published by the Free Software Foundation.
158 |
159 | If the Library as you received it specifies that a proxy can decide
160 | whether future versions of the GNU Lesser General Public License shall
161 | apply, that proxy's public statement of acceptance of any version is
162 | permanent authorization for you to choose that version for the
163 | Library.
164 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # About
2 |
3 | This project provides examples on how to use osm4j.
4 |
5 | ## License
6 |
7 | This library is released under the terms of the GNU Lesser General Public
8 | License.
9 |
10 | See [LGPL.md](LGPL.md) and [GPL.md](GPL.md) for details.
11 |
12 | ## Using with Eclipse
13 |
14 | Create an Eclipse project like this:
15 |
16 | ./gradlew cleanEclipse eclipse
17 |
18 | After that, go to the 'Git Repositories' view, add the local repository to
19 | the list. Then right click the repository and select 'Import Projects'.
20 |
21 | ## Tutorial
22 |
23 | Check out the
24 | [Tutorial](http://www.jaryard.com/projects/osm4j/tutorial/index.html)
25 | to get an in-depth explanation of the examples in this project.
26 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | wrapper {
2 | gradleVersion = '7.6.1'
3 | }
4 |
5 | apply plugin: 'java'
6 | apply plugin: 'eclipse'
7 |
8 | if (project.hasProperty("topobyte")) {
9 | apply from: 'file:///' + System.getProperty("user.home") \
10 | + '/.gradle/topobyte.gradle'
11 | }
12 |
13 | group = pGroup
14 | version = pVersion
15 |
16 | repositories {
17 | maven {
18 | url 'https://mvn.topobyte.de'
19 | }
20 | maven {
21 | url 'https://mvn.slimjars.com'
22 | }
23 | mavenCentral()
24 | }
25 |
26 | dependencies {
27 | implementation 'de.topobyte:osm4j-xml:1.2.0'
28 | implementation 'de.topobyte:osm4j-pbf:1.2.0'
29 | implementation 'de.topobyte:osm4j-tbo:1.2.0'
30 | implementation 'de.topobyte:osm4j-geometry:1.2.0'
31 |
32 | implementation 'de.topobyte:adt-geo:0.1.0'
33 | implementation 'de.topobyte:jts2awt:0.1.0'
34 | implementation 'de.topobyte:mercator-image:0.1.0'
35 |
36 | implementation 'org.wololo:jts2geojson:0.14.3'
37 |
38 | implementation 'org.apache.commons:commons-compress:1.8'
39 | implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.1'
40 | implementation 'joda-time:joda-time:2.9.7'
41 | implementation 'com.google.guava:guava:19.0'
42 |
43 | implementation 'org.slf4j:slf4j-api:1.6.1'
44 | runtimeOnly 'org.slf4j:slf4j-log4j12:1.6.1'
45 | runtimeOnly 'log4j:log4j:1.2.16'
46 | }
47 |
48 | task sourcesJar(type: Jar, dependsOn: classes) {
49 | classifier = 'sources'
50 | from sourceSets.main.allSource
51 | }
52 |
53 | artifacts {
54 | archives sourcesJar
55 | }
56 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | pName=osm4j-examples
2 | pGroup=de.topobyte
3 | pVersion=0.0.1
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/topobyte/osm4j-examples/8588dbadd054cacbd5f8d3ade20cec98f1d386cc/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
4 | networkTimeout=10000
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | # This is normally unused
84 | # shellcheck disable=SC2034
85 | APP_BASE_NAME=${0##*/}
86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
87 |
88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 |
142 | # Increase the maximum file descriptors if we can.
143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144 | case $MAX_FD in #(
145 | max*)
146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147 | # shellcheck disable=SC3045
148 | MAX_FD=$( ulimit -H -n ) ||
149 | warn "Could not query maximum file descriptor limit"
150 | esac
151 | case $MAX_FD in #(
152 | '' | soft) :;; #(
153 | *)
154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155 | # shellcheck disable=SC3045
156 | ulimit -n "$MAX_FD" ||
157 | warn "Could not set maximum file descriptor limit to $MAX_FD"
158 | esac
159 | fi
160 |
161 | # Collect all arguments for the java command, stacking in reverse order:
162 | # * args from the command line
163 | # * the main class name
164 | # * -classpath
165 | # * -D...appname settings
166 | # * --module-path (only if needed)
167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
168 |
169 | # For Cygwin or MSYS, switch paths to Windows format before running java
170 | if "$cygwin" || "$msys" ; then
171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
173 |
174 | JAVACMD=$( cygpath --unix "$JAVACMD" )
175 |
176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
177 | for arg do
178 | if
179 | case $arg in #(
180 | -*) false ;; # don't mess with options #(
181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
182 | [ -e "$t" ] ;; #(
183 | *) false ;;
184 | esac
185 | then
186 | arg=$( cygpath --path --ignore --mixed "$arg" )
187 | fi
188 | # Roll the args list around exactly as many times as the number of
189 | # args, so each arg winds up back in the position where it started, but
190 | # possibly modified.
191 | #
192 | # NB: a `for` loop captures its iteration list before it begins, so
193 | # changing the positional parameters here affects neither the number of
194 | # iterations, nor the values presented in `arg`.
195 | shift # remove old arg
196 | set -- "$@" "$arg" # push replacement arg
197 | done
198 | fi
199 |
200 | # Collect all arguments for the java command;
201 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
202 | # shell script including quotes and variable substitutions, so put them in
203 | # double quotes to make sure that they get re-expanded; and
204 | # * put everything else in single quotes, so that it's not re-expanded.
205 |
206 | set -- \
207 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
208 | -classpath "$CLASSPATH" \
209 | org.gradle.wrapper.GradleWrapperMain \
210 | "$@"
211 |
212 | # Stop when "xargs" is not available.
213 | if ! command -v xargs >/dev/null 2>&1
214 | then
215 | die "xargs is not available"
216 | fi
217 |
218 | # Use "xargs" to parse quoted args.
219 | #
220 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
221 | #
222 | # In Bash we could simply go:
223 | #
224 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
225 | # set -- "${ARGS[@]}" "$@"
226 | #
227 | # but POSIX shell has neither arrays nor command substitution, so instead we
228 | # post-process each arg (as a line of input to sed) to backslash-escape any
229 | # character that might be a shell metacharacter, then use eval to reverse
230 | # that process (while maintaining the separation between arguments), and wrap
231 | # the whole thing up as a single "set" statement.
232 | #
233 | # This will of course break if any of these variables contains a newline or
234 | # an unmatched quote.
235 | #
236 |
237 | eval "set -- $(
238 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
239 | xargs -n1 |
240 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
241 | tr '\n' ' '
242 | )" '"$@"'
243 |
244 | exec "$JAVACMD" "$@"
245 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%"=="" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%"=="" set DIRNAME=.
29 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo.
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48 | echo.
49 | echo Please set the JAVA_HOME variable in your environment to match the
50 | echo location of your Java installation.
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo.
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62 | echo.
63 | echo Please set the JAVA_HOME variable in your environment to match the
64 | echo location of your Java installation.
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/output/relation-122895.geojson:
--------------------------------------------------------------------------------
1 | {
2 | "type" : "Feature",
3 | "properties" : {
4 | "name" : "Blaues Wunder",
5 | "type" : "multipolygon"
6 | },
7 | "geometry" : {
8 | "type" : "MultiPolygon",
9 | "coordinates" : [ [ [ [ 13.2077736, 52.6330749 ], [ 13.2077811, 52.6330802 ], [ 13.2077758, 52.633094 ], [ 13.2077669, 52.6331071 ], [ 13.2077542, 52.633119 ], [ 13.2077381, 52.6331294 ], [ 13.2077192, 52.6331377 ], [ 13.2076981, 52.6331438 ], [ 13.2076756, 52.6331475 ], [ 13.2076525, 52.6331487 ], [ 13.2076451, 52.6331437 ], [ 13.2073873, 52.6332817 ], [ 13.2068207, 52.6328897 ], [ 13.2070788, 52.6327517 ], [ 13.2070715, 52.6327466 ], [ 13.2070779, 52.632731 ], [ 13.207089, 52.6327163 ], [ 13.2071049, 52.6327034 ], [ 13.2071248, 52.6326927 ], [ 13.2071479, 52.6326848 ], [ 13.2071732, 52.63268 ], [ 13.2071995, 52.6326783 ], [ 13.2072068, 52.6326833 ], [ 13.2074649, 52.6325452 ], [ 13.2080312, 52.6329371 ], [ 13.2077736, 52.6330749 ] ], [ [ 13.2072557, 52.6329074 ], [ 13.2074367, 52.6328099 ], [ 13.2075972, 52.6329196 ], [ 13.2074162, 52.6330171 ], [ 13.2072557, 52.6329074 ] ] ], [ [ [ 13.2066865, 52.6335848 ], [ 13.2071467, 52.6333394 ], [ 13.206794, 52.6333266 ], [ 13.2068012, 52.6332723 ], [ 13.2071504, 52.6332876 ], [ 13.2067443, 52.6330045 ], [ 13.2066865, 52.6335848 ] ] ], [ [ [ 13.2089258, 52.6340292 ], [ 13.2089183, 52.634024 ], [ 13.2086601, 52.6341621 ], [ 13.2080935, 52.63377 ], [ 13.2083518, 52.6336319 ], [ 13.2083444, 52.6336268 ], [ 13.2083497, 52.633613 ], [ 13.2083586, 52.6336 ], [ 13.2083714, 52.6335881 ], [ 13.2083875, 52.6335778 ], [ 13.2084063, 52.6335695 ], [ 13.2084273, 52.6335634 ], [ 13.2084498, 52.6335598 ], [ 13.2084728, 52.6335586 ], [ 13.2084799, 52.6335634 ], [ 13.2087378, 52.6334255 ], [ 13.2093045, 52.6338175 ], [ 13.2090464, 52.6339555 ], [ 13.2090537, 52.6339607 ], [ 13.2090475, 52.6339763 ], [ 13.2090364, 52.633991 ], [ 13.2090205, 52.634004 ], [ 13.2090006, 52.6340147 ], [ 13.2089775, 52.6340227 ], [ 13.2089522, 52.6340275 ], [ 13.2089258, 52.6340292 ] ], [ [ 13.2085282, 52.6337868 ], [ 13.2087099, 52.6336898 ], [ 13.2088705, 52.6338006 ], [ 13.2086888, 52.6338976 ], [ 13.2085282, 52.6337868 ] ] ], [ [ [ 13.2074843, 52.6341464 ], [ 13.2079472, 52.6338994 ], [ 13.207924, 52.6341117 ], [ 13.2080072, 52.634115 ], [ 13.2080336, 52.6338998 ], [ 13.2084403, 52.634186 ], [ 13.2074843, 52.6341464 ] ] ], [ [ [ 13.2086193, 52.6325596 ], [ 13.2081428, 52.6328141 ], [ 13.2081641, 52.6326027 ], [ 13.2080801, 52.6325998 ], [ 13.2080562, 52.6328098 ], [ 13.2076378, 52.632523 ], [ 13.2086193, 52.6325596 ] ] ], [ [ [ 13.2093498, 52.633701 ], [ 13.2094121, 52.633103 ], [ 13.2089427, 52.6333541 ], [ 13.2092887, 52.6333678 ], [ 13.2092836, 52.6334203 ], [ 13.208936, 52.6334062 ], [ 13.2093498, 52.633701 ] ] ], [ [ [ 13.2073, 52.634109 ], [ 13.2070731, 52.6339521 ], [ 13.2070645, 52.6339566 ], [ 13.2070388, 52.6339529 ], [ 13.2070147, 52.6339461 ], [ 13.2069935, 52.6339365 ], [ 13.2069759, 52.6339244 ], [ 13.2069629, 52.6339103 ], [ 13.2069549, 52.633895 ], [ 13.2069518, 52.633879 ], [ 13.2069606, 52.6338742 ], [ 13.2067336, 52.6337172 ], [ 13.2073776, 52.6333726 ], [ 13.2076043, 52.6335295 ], [ 13.2076126, 52.633525 ], [ 13.2076353, 52.6335281 ], [ 13.2076567, 52.6335335 ], [ 13.2076763, 52.6335412 ], [ 13.2076932, 52.633551 ], [ 13.207707, 52.6335624 ], [ 13.2077172, 52.6335751 ], [ 13.2077233, 52.6335887 ], [ 13.2077257, 52.6336028 ], [ 13.207717, 52.6336074 ], [ 13.2079439, 52.6337644 ], [ 13.2073, 52.634109 ] ], [ [ 13.2071685, 52.6337343 ], [ 13.2073495, 52.6336373 ], [ 13.2075095, 52.6337473 ], [ 13.2073285, 52.6338443 ], [ 13.2071685, 52.6337343 ] ] ], [ [ [ 13.2083994, 52.6331041 ], [ 13.2084078, 52.6330996 ], [ 13.2081813, 52.6329428 ], [ 13.2088253, 52.6325982 ], [ 13.2090523, 52.6327553 ], [ 13.209061, 52.6327506 ], [ 13.2090835, 52.6327538 ], [ 13.2091049, 52.6327592 ], [ 13.2091243, 52.6327669 ], [ 13.2091411, 52.6327766 ], [ 13.2091548, 52.632788 ], [ 13.2091649, 52.6328007 ], [ 13.209171, 52.6328143 ], [ 13.2091734, 52.6328283 ], [ 13.2091646, 52.6328329 ], [ 13.2093917, 52.63299 ], [ 13.2087475, 52.6333346 ], [ 13.2085206, 52.6331776 ], [ 13.2085124, 52.6331821 ], [ 13.2084897, 52.633179 ], [ 13.2084682, 52.6331735 ], [ 13.2084486, 52.6331658 ], [ 13.2084317, 52.6331561 ], [ 13.2084179, 52.6331446 ], [ 13.2084078, 52.6331319 ], [ 13.2084017, 52.6331182 ], [ 13.2083994, 52.6331041 ] ], [ [ 13.2086167, 52.6329597 ], [ 13.2087974, 52.6328631 ], [ 13.2089568, 52.6329731 ], [ 13.208776, 52.6330696 ], [ 13.2086167, 52.6329597 ] ] ] ]
10 | }
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/output/relation-16566.geojson:
--------------------------------------------------------------------------------
1 | {
2 | "type" : "Feature",
3 | "properties" : {
4 | "geographical_region" : "Berliner Urstromtal",
5 | "ref" : "0101",
6 | "timezone" : "Europe/Berlin",
7 | "admin_level" : "10",
8 | "name:ru" : "Митте",
9 | "source" : "http://wiki.openstreetmap.org/wiki/Import/Catalogue/Kreisgrenzen_Deutschland_2005",
10 | "name" : "Mitte",
11 | "wikipedia" : "de:Berlin-Mitte",
12 | "name:de" : "Mitte",
13 | "place" : "suburb",
14 | "type" : "boundary",
15 | "name:prefix" : "Ortsteil",
16 | "boundary" : "administrative"
17 | },
18 | "geometry" : {
19 | "type" : "MultiPolygon",
20 | "coordinates" : [ [ [ [ 13.4218109, 52.505042 ], [ 13.4215419, 52.5050785 ], [ 13.4211305, 52.5051754 ], [ 13.4206174, 52.5053214 ], [ 13.4194305, 52.5056491 ], [ 13.4191101, 52.5052037 ], [ 13.4189981, 52.5051182 ], [ 13.4189245, 52.50508 ], [ 13.4189443, 52.5050603 ], [ 13.4185318, 52.504969 ], [ 13.4185186, 52.5049867 ], [ 13.4184001, 52.5049933 ], [ 13.4182136, 52.5050177 ], [ 13.4176016, 52.5041685 ], [ 13.4168472, 52.5043798 ], [ 13.4166967, 52.5044216 ], [ 13.4166273, 52.5044415 ], [ 13.4149072, 52.5049185 ], [ 13.4145925, 52.5047921 ], [ 13.4146097, 52.5046798 ], [ 13.4140723, 52.5040371 ], [ 13.4115252, 52.5048911 ], [ 13.4108939, 52.5057255 ], [ 13.4099694, 52.5069278 ], [ 13.4080301, 52.5061832 ], [ 13.4078501, 52.5063267 ], [ 13.4074002, 52.5066723 ], [ 13.4073589, 52.5066478 ], [ 13.4064044, 52.5073853 ], [ 13.4059383, 52.5077299 ], [ 13.4057965, 52.5078345 ], [ 13.4056214, 52.5079615 ], [ 13.4052837, 52.5082102 ], [ 13.4046343, 52.5079228 ], [ 13.4045782, 52.5078856 ], [ 13.4044429, 52.5077718 ], [ 13.4043012, 52.5078617 ], [ 13.404037, 52.5079941 ], [ 13.4036335, 52.5081778 ], [ 13.4027619, 52.5085334 ], [ 13.4021013, 52.5087285 ], [ 13.4012638, 52.5090381 ], [ 13.4009175, 52.5091378 ], [ 13.4002283, 52.5093816 ], [ 13.4001886, 52.5093755 ], [ 13.4000254, 52.509151 ], [ 13.3999387, 52.5090282 ], [ 13.3997671, 52.5088 ], [ 13.3992301, 52.5080775 ], [ 13.3987944, 52.5080917 ], [ 13.3987719, 52.5081134 ], [ 13.3981888, 52.5080789 ], [ 13.3942839, 52.5078332 ], [ 13.3922257, 52.5077033 ], [ 13.390484, 52.5075985 ], [ 13.3898682, 52.5075711 ], [ 13.3868833, 52.5073951 ], [ 13.3857617, 52.5073286 ], [ 13.3789222, 52.5069995 ], [ 13.3776503, 52.5079658 ], [ 13.3773602, 52.508338 ], [ 13.3770793, 52.5085774 ], [ 13.3769149, 52.5087131 ], [ 13.3768341, 52.5087702 ], [ 13.3767412, 52.5088821 ], [ 13.3767026, 52.508935 ], [ 13.3766653, 52.50901 ], [ 13.3766446, 52.5090894 ], [ 13.3765998, 52.5092786 ], [ 13.3765815, 52.5094194 ], [ 13.3765714, 52.5095951 ], [ 13.3765591, 52.5097671 ], [ 13.3765444, 52.509964 ], [ 13.3765597, 52.5100977 ], [ 13.3765913, 52.51024 ], [ 13.3766273, 52.5103878 ], [ 13.376682, 52.5106524 ], [ 13.3766905, 52.5107291 ], [ 13.3766994, 52.5107584 ], [ 13.3770325, 52.5122394 ], [ 13.3770324, 52.512359 ], [ 13.3768188, 52.5124089 ], [ 13.376822, 52.5124798 ], [ 13.3768505, 52.5129279 ], [ 13.3769876, 52.5135825 ], [ 13.377373, 52.5156371 ], [ 13.377218, 52.515679 ], [ 13.3769605, 52.5157626 ], [ 13.3768146, 52.5158305 ], [ 13.3766945, 52.5159349 ], [ 13.3766172, 52.5160551 ], [ 13.3765769, 52.5162016 ], [ 13.3765486, 52.5163006 ], [ 13.376567, 52.5163453 ], [ 13.3765915, 52.516405 ], [ 13.3766687, 52.5165095 ], [ 13.3767631, 52.5165774 ], [ 13.3769262, 52.516661 ], [ 13.3770721, 52.5167236 ], [ 13.3771837, 52.5167654 ], [ 13.3772438, 52.5168229 ], [ 13.3772622, 52.5168769 ], [ 13.3769867, 52.5174033 ], [ 13.3768575, 52.5176951 ], [ 13.3769827, 52.51795 ], [ 13.3770025, 52.519565 ], [ 13.3769629, 52.5195876 ], [ 13.3767404, 52.5196987 ], [ 13.3766847, 52.5197326 ], [ 13.3765208, 52.5198502 ], [ 13.3763704, 52.5199859 ], [ 13.3761487, 52.5203079 ], [ 13.3760324, 52.5207919 ], [ 13.3759871, 52.5209689 ], [ 13.3759305, 52.5212096 ], [ 13.3758532, 52.5213208 ], [ 13.3756265, 52.5215711 ], [ 13.3754414, 52.5217554 ], [ 13.3753408, 52.5218379 ], [ 13.3752652, 52.5218999 ], [ 13.3751577, 52.5219602 ], [ 13.374941, 52.5220811 ], [ 13.3747722, 52.5221645 ], [ 13.3745792, 52.5222586 ], [ 13.3744832, 52.5223077 ], [ 13.3742649, 52.5224049 ], [ 13.3740103, 52.5225033 ], [ 13.3739122, 52.522534 ], [ 13.3738061, 52.5225697 ], [ 13.3736545, 52.5226133 ], [ 13.3735818, 52.5226293 ], [ 13.3733999, 52.5226724 ], [ 13.3732443, 52.5226994 ], [ 13.37303, 52.5227345 ], [ 13.3728572, 52.5227523 ], [ 13.3726844, 52.5227701 ], [ 13.3725652, 52.5227794 ], [ 13.3724409, 52.522788 ], [ 13.3723105, 52.5227917 ], [ 13.3721139, 52.5228012 ], [ 13.3719099, 52.5228 ], [ 13.3717882, 52.5227968 ], [ 13.3716988, 52.5248226 ], [ 13.3718132, 52.5248248 ], [ 13.3717832, 52.5253972 ], [ 13.3710361, 52.5253827 ], [ 13.3709782, 52.5264857 ], [ 13.3735465, 52.5265355 ], [ 13.3736635, 52.5266883 ], [ 13.3738527, 52.5269409 ], [ 13.373859, 52.5271324 ], [ 13.3738497, 52.5273406 ], [ 13.3737816, 52.5275237 ], [ 13.3736422, 52.5277966 ], [ 13.3735728, 52.5278868 ], [ 13.3734264, 52.5280606 ], [ 13.3730627, 52.5284107 ], [ 13.3723509, 52.5290227 ], [ 13.3717961, 52.5295797 ], [ 13.3711895, 52.5301745 ], [ 13.3708461, 52.5305822 ], [ 13.3705772, 52.5309496 ], [ 13.370085, 52.5316064 ], [ 13.3697913, 52.5319939 ], [ 13.3694148, 52.5324242 ], [ 13.3692949, 52.5325098 ], [ 13.3689143, 52.5328973 ], [ 13.3685117, 52.533293 ], [ 13.3682715, 52.5333139 ], [ 13.3680629, 52.5335222 ], [ 13.3678566, 52.5337283 ], [ 13.3658599, 52.5356602 ], [ 13.3665589, 52.5359129 ], [ 13.3667012, 52.5360631 ], [ 13.3678819, 52.5366213 ], [ 13.3686093, 52.5359913 ], [ 13.3729884, 52.5380288 ], [ 13.3737572, 52.5375186 ], [ 13.374555, 52.537033 ], [ 13.3749244, 52.537325 ], [ 13.3761674, 52.5380617 ], [ 13.376127, 52.5380868 ], [ 13.3763416, 52.5382119 ], [ 13.3794935, 52.5401369 ], [ 13.379742, 52.5401484 ], [ 13.3798263, 52.5400673 ], [ 13.3800653, 52.5397546 ], [ 13.3821339, 52.5377677 ], [ 13.3831012, 52.5369416 ], [ 13.3849179, 52.5354542 ], [ 13.3863569, 52.5343048 ], [ 13.3869606, 52.5338499 ], [ 13.3874471, 52.5334749 ], [ 13.3881904, 52.5337906 ], [ 13.3895384, 52.5349816 ], [ 13.3898557, 52.5352616 ], [ 13.3901143, 52.5354558 ], [ 13.3931312, 52.537447 ], [ 13.3955801, 52.5381553 ], [ 13.3979548, 52.538801 ], [ 13.3990111, 52.5390995 ], [ 13.3994175, 52.5392103 ], [ 13.4000276, 52.539384 ], [ 13.40028, 52.5394551 ], [ 13.4005455, 52.5395329 ], [ 13.4015572, 52.5398222 ], [ 13.4035266, 52.5402138 ], [ 13.4041547, 52.5403892 ], [ 13.4042237, 52.5404067 ], [ 13.4045527, 52.5402595 ], [ 13.4047002, 52.540185 ], [ 13.4053577, 52.5388355 ], [ 13.4055366, 52.5384811 ], [ 13.4058863, 52.5377837 ], [ 13.4065804, 52.536422 ], [ 13.4069181, 52.5357102 ], [ 13.4069768, 52.5356028 ], [ 13.4074838, 52.5346907 ], [ 13.4078028, 52.5345646 ], [ 13.4083548, 52.5343478 ], [ 13.4064339, 52.5323628 ], [ 13.4060436, 52.5310551 ], [ 13.4059576, 52.530765 ], [ 13.4060629, 52.5305863 ], [ 13.4058745, 52.5303766 ], [ 13.4055381, 52.5296496 ], [ 13.4073923, 52.5293459 ], [ 13.4082053, 52.5292086 ], [ 13.4094567, 52.5289251 ], [ 13.4100859, 52.5287966 ], [ 13.4114239, 52.5285597 ], [ 13.4118819, 52.5284263 ], [ 13.4120826, 52.5283652 ], [ 13.4123258, 52.5283026 ], [ 13.4155634, 52.5273999 ], [ 13.4159556, 52.5271846 ], [ 13.4161457, 52.5270836 ], [ 13.4166868, 52.5268757 ], [ 13.4167082, 52.5268863 ], [ 13.4169053, 52.526796 ], [ 13.4168897, 52.5267836 ], [ 13.4175618, 52.5264858 ], [ 13.41821, 52.5261978 ], [ 13.4197534, 52.5255461 ], [ 13.4197996, 52.5255288 ], [ 13.4217536, 52.5247551 ], [ 13.422336, 52.524527 ], [ 13.4237733, 52.5239632 ], [ 13.4240706, 52.5238552 ], [ 13.424745, 52.5236397 ], [ 13.4254333, 52.5234391 ], [ 13.4254847, 52.5234462 ], [ 13.425881, 52.5233521 ], [ 13.4262749, 52.5233038 ], [ 13.426501, 52.5232938 ], [ 13.4265191, 52.5229415 ], [ 13.4260028, 52.5229219 ], [ 13.4259104, 52.5228316 ], [ 13.4255523, 52.5227924 ], [ 13.427648, 52.5218833 ], [ 13.4286516, 52.5214498 ], [ 13.4291793, 52.5212255 ], [ 13.4291879, 52.5212028 ], [ 13.4287208, 52.520244 ], [ 13.4283998, 52.5195865 ], [ 13.427473, 52.519607 ], [ 13.4272839, 52.5196462 ], [ 13.4269188, 52.5197438 ], [ 13.4264469, 52.5191356 ], [ 13.4258857, 52.5183374 ], [ 13.4262864, 52.5182252 ], [ 13.4264656, 52.5181717 ], [ 13.4265929, 52.5181171 ], [ 13.4270187, 52.5179385 ], [ 13.4266276, 52.5173261 ], [ 13.4259571, 52.5162893 ], [ 13.4257778, 52.5159913 ], [ 13.4265029, 52.5158327 ], [ 13.4256938, 52.5149428 ], [ 13.4255792, 52.5148191 ], [ 13.4251965, 52.5144161 ], [ 13.4246173, 52.5138765 ], [ 13.4242813, 52.5135692 ], [ 13.4240861, 52.5133932 ], [ 13.42399, 52.5133045 ], [ 13.4233569, 52.5126682 ], [ 13.4232627, 52.5120616 ], [ 13.4235907, 52.5118554 ], [ 13.4242054, 52.5115003 ], [ 13.4249204, 52.5111143 ], [ 13.4255866, 52.5107436 ], [ 13.4260889, 52.5104434 ], [ 13.4271416, 52.5098435 ], [ 13.4277159, 52.5095111 ], [ 13.4283935, 52.5090733 ], [ 13.4286965, 52.509001 ], [ 13.4288928, 52.5089875 ], [ 13.42917, 52.5088441 ], [ 13.4291869, 52.5088211 ], [ 13.4292032, 52.5087282 ], [ 13.4292376, 52.5086726 ], [ 13.4294017, 52.5085714 ], [ 13.4290283, 52.5080363 ], [ 13.4288144, 52.5079776 ], [ 13.4283665, 52.5073345 ], [ 13.4281137, 52.5069735 ], [ 13.4279958, 52.5068044 ], [ 13.4278537, 52.5066013 ], [ 13.427689, 52.5063666 ], [ 13.4276139, 52.5062578 ], [ 13.427499, 52.5060935 ], [ 13.4271997, 52.5056674 ], [ 13.4269722, 52.5057312 ], [ 13.4267083, 52.5057986 ], [ 13.4261207, 52.5055508 ], [ 13.4258215, 52.5054247 ], [ 13.4255041, 52.5053239 ], [ 13.4252194, 52.5052477 ], [ 13.4249569, 52.5051819 ], [ 13.4247139, 52.505133 ], [ 13.4244748, 52.5050933 ], [ 13.4243499, 52.5050748 ], [ 13.4239799, 52.5050293 ], [ 13.4237378, 52.505009 ], [ 13.4233526, 52.5049868 ], [ 13.423038, 52.50498 ], [ 13.4226642, 52.5049872 ], [ 13.4223011, 52.5050078 ], [ 13.4220787, 52.5050273 ], [ 13.4218109, 52.505042 ] ] ] ]
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = pName
2 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/ListRestaurantsFromOverpassInBoundingBox.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.Map;
24 |
25 | import de.topobyte.osm4j.core.access.OsmIterator;
26 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
27 | import de.topobyte.osm4j.core.model.iface.EntityType;
28 | import de.topobyte.osm4j.core.model.iface.OsmNode;
29 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
30 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
31 |
32 | public class ListRestaurantsFromOverpassInBoundingBox
33 | {
34 |
35 | public static void main(String[] args) throws IOException
36 | {
37 | // Define a query to retrieve some data
38 | String query = "http://www.overpass-api.de/api/xapi?*[bbox="
39 | + "13.465661,52.504055,13.469817,52.506204]";
40 |
41 | // Open a stream
42 | InputStream input = new URL(query).openStream();
43 |
44 | // Create a reader for XML data
45 | OsmIterator iterator = new OsmXmlIterator(input, false);
46 |
47 | // Iterate contained entities
48 | for (EntityContainer container : iterator) {
49 |
50 | // Only use nodes
51 | if (container.getType() == EntityType.Node) {
52 |
53 | // Get the node from the container
54 | OsmNode node = (OsmNode) container.getEntity();
55 |
56 | // Convert the node's tags to a map
57 | Map tags = OsmModelUtil.getTagsAsMap(node);
58 |
59 | // Get the value for the 'amenity' key
60 | String amenity = tags.get("amenity");
61 |
62 | // Check if this is a restaurant
63 | boolean isRestaurant = amenity != null
64 | && amenity.equals("restaurant");
65 |
66 | // If yes, print name and coordinate
67 | if (isRestaurant) {
68 | System.out.println(String.format("%s: %f, %f",
69 | tags.get("name"),
70 | node.getLatitude(),
71 | node.getLongitude()
72 | ));
73 | }
74 | }
75 | }
76 | }
77 |
78 | }
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/history/GeofabrikUtils.java:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.history;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.util.Properties;
23 |
24 | import org.apache.hc.client5.http.cookie.BasicCookieStore;
25 | import org.apache.hc.client5.http.cookie.CookieStore;
26 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
27 | import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
28 | import org.apache.hc.client5.http.impl.cookie.BasicClientCookie;
29 |
30 | public class GeofabrikUtils
31 | {
32 |
33 | public static CloseableHttpClient createClientWithCookie()
34 | throws IOException
35 | {
36 | String cookieData = null;
37 |
38 | try (InputStream input = Thread.currentThread().getContextClassLoader()
39 | .getResourceAsStream("secure.properties")) {
40 | Properties properties = new Properties();
41 | properties.load(input);
42 | cookieData = properties.getProperty("geofabrik.cookie");
43 | }
44 |
45 | if (cookieData == null) {
46 | System.out.println(
47 | "To access internal OSM files from Geofabrik, you need to add a cookie definition");
48 | System.out.println("to `src/main/resources/secure.properties`:");
49 | System.out.println();
50 | System.out
51 | .println("geofabrik.cookie=login|2018-06-15|ABC...0123==");
52 | System.out.println();
53 | System.out.println(
54 | "To determine what to add to that file, navigate to");
55 | System.out.println("https://osm-internal.download.geofabrik.de/");
56 | System.out.println(
57 | "then login to that page. Then when loading that page, inspect");
58 | System.out.println(
59 | "the headers the browser sends to the website in the developer");
60 | System.out.println(
61 | "tools by inspecting the request headers in the network tab.");
62 | System.out.println();
63 | }
64 |
65 | CookieStore cookieStore = new BasicCookieStore();
66 | BasicClientCookie cookie = new BasicClientCookie("gf_download_oauth",
67 | cookieData);
68 | cookie.setDomain("osm-internal.download.geofabrik.de");
69 | cookieStore.addCookie(cookie);
70 |
71 | CloseableHttpClient client = HttpClientBuilder.create()
72 | .setDefaultCookieStore(cookieStore).build();
73 | return client;
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/history/HistoryBasics.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.history;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.util.List;
23 |
24 | import org.apache.hc.client5.http.classic.methods.HttpGet;
25 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
26 | import org.apache.hc.client5.http.protocol.HttpClientContext;
27 | import org.apache.hc.core5.http.HttpStatus;
28 | import org.joda.time.format.DateTimeFormat;
29 | import org.joda.time.format.DateTimeFormatter;
30 |
31 | import de.topobyte.osm4j.core.access.OsmIterator;
32 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
33 | import de.topobyte.osm4j.core.model.iface.EntityType;
34 | import de.topobyte.osm4j.core.model.iface.OsmMetadata;
35 | import de.topobyte.osm4j.core.model.iface.OsmNode;
36 | import de.topobyte.osm4j.core.model.iface.OsmTag;
37 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
38 | import de.topobyte.osm4j.pbf.seq.PbfIterator;
39 |
40 | public class HistoryBasics
41 | {
42 |
43 | public static void main(String[] args) throws IOException
44 | {
45 | // Define a URL to retrieve some data
46 | String url = "https://osm-internal.download.geofabrik.de/europe/germany/bremen-internal.osh.pbf";
47 |
48 | CloseableHttpClient client = GeofabrikUtils.createClientWithCookie();
49 |
50 | HttpClientContext context = HttpClientContext.create();
51 | HttpGet request = new HttpGet(url);
52 |
53 | client.execute(request, context, response -> {
54 | if (response.getCode() == HttpStatus.SC_OK) {
55 | InputStream input = response.getEntity().getContent();
56 | process(input);
57 | } else {
58 | System.out.println(
59 | "Accessing the history file was not successful");
60 | }
61 | return null;
62 | });
63 | }
64 |
65 | private static void process(InputStream input)
66 | {
67 | // Create an iterator for PBF data
68 | OsmIterator iterator = new PbfIterator(input, true);
69 |
70 | // We will use this formatter to print timestamps
71 | DateTimeFormatter formatter = DateTimeFormat
72 | .forPattern("YYYY-MM-dd HH:mm");
73 |
74 | // Iterate all elements
75 | for (EntityContainer container : iterator) {
76 |
77 | // Check if the element is a node
78 | if (container.getType() == EntityType.Node) {
79 |
80 | // Cast the entity to OsmNode
81 | OsmNode node = (OsmNode) container.getEntity();
82 | OsmMetadata metadata = node.getMetadata();
83 |
84 | // Get some metadata info
85 | boolean visible = metadata.isVisible();
86 | long timestamp = metadata.getTimestamp();
87 |
88 | // Also get the tags as a list
89 | List extends OsmTag> tags = OsmModelUtil.getTagsAsList(node);
90 |
91 | // Print information
92 | System.out.println(String.format(
93 | "id: %d, lat: %.6f, lon: %.6f, visible: %b, timestamp: %s, tags: %s",
94 | node.getId(), node.getLatitude(), node.getLongitude(),
95 | visible, formatter.print(timestamp), tags));
96 | }
97 | }
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/history/HistoryOfRestaurants.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.history;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.util.Map;
23 |
24 | import org.apache.hc.client5.http.classic.methods.HttpGet;
25 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
26 | import org.apache.hc.client5.http.protocol.HttpClientContext;
27 | import org.apache.hc.core5.http.HttpStatus;
28 | import org.joda.time.format.DateTimeFormat;
29 | import org.joda.time.format.DateTimeFormatter;
30 |
31 | import com.google.common.collect.Sets;
32 | import com.google.common.collect.Sets.SetView;
33 |
34 | import de.topobyte.osm4j.core.access.OsmIterator;
35 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
36 | import de.topobyte.osm4j.core.model.iface.EntityType;
37 | import de.topobyte.osm4j.core.model.iface.OsmNode;
38 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
39 | import de.topobyte.osm4j.pbf.seq.PbfIterator;
40 |
41 | public class HistoryOfRestaurants
42 | {
43 |
44 | public static void main(String[] args) throws IOException
45 | {
46 | // Define a URL to retrieve some data
47 | String url = "https://osm-internal.download.geofabrik.de/europe/germany/bremen-internal.osh.pbf";
48 |
49 | CloseableHttpClient client = GeofabrikUtils.createClientWithCookie();
50 |
51 | HttpClientContext context = HttpClientContext.create();
52 | HttpGet request = new HttpGet(url);
53 |
54 | client.execute(request, context, response -> {
55 | if (response.getCode() == HttpStatus.SC_OK) {
56 | InputStream input = response.getEntity().getContent();
57 | process(input);
58 | } else {
59 | System.out.println(
60 | "Accessing the history file was not successful");
61 | }
62 | return null;
63 | });
64 | }
65 |
66 | private static void process(InputStream input)
67 | {
68 | // Create an iterator for PBF data
69 | OsmIterator iterator = new PbfIterator(input, true);
70 |
71 | // We will use this formatter to print timestamps
72 | DateTimeFormatter pattern = DateTimeFormat
73 | .forPattern("YYYY-MM-dd HH:mm");
74 |
75 | // Here we store information about the previous node so that we can
76 | // compute the difference between the current node and the previous one
77 | long previousId = 0;
78 | OsmNode previousNode = null;
79 | Map previousTags = null;
80 | boolean wasRestaurantBefore = false;
81 |
82 | // Iterate all elements
83 | for (EntityContainer container : iterator) {
84 |
85 | // Check if the element is a node
86 | if (container.getType() == EntityType.Node) {
87 |
88 | // Cast the entity to OsmNode
89 | OsmNode node = (OsmNode) container.getEntity();
90 | long timestamp = node.getMetadata().getTimestamp();
91 |
92 | // This is an update, i.e. a later instance of the same node, if
93 | // the previous node's id and the current node's id are the same
94 | boolean isUpdate = previousId == node.getId();
95 | previousId = node.getId();
96 |
97 | // Here we store the values from variables named previous* to
98 | // last* so that we can overwrite the previous* variables and
99 | // still access their values using their last* counterparts.
100 | OsmNode lastNode = previousNode;
101 | previousNode = node;
102 |
103 | Map currentTags = OsmModelUtil
104 | .getTagsAsMap(node);
105 | Map lastTags = previousTags;
106 | previousTags = currentTags;
107 |
108 | // Determine if the current node is a restaurant, i.e. has tag
109 | // 'amenity=restaurant'
110 | boolean isRestaurant = isRestaurant(currentTags);
111 |
112 | // If this is not an update, we reset the wasRestaurant flag
113 | // which might still be true from a different restaurant
114 | // encountered before.
115 | if (!isUpdate) {
116 | wasRestaurantBefore = false;
117 | }
118 |
119 | // If the current node is a restaurant, we set the flag so that
120 | // in the next round we will now that an update to this node is
121 | // on a restaurant node.
122 | if (isRestaurant) {
123 | wasRestaurantBefore = true;
124 | }
125 |
126 | // If this is not a restaurant and also has not been one in the
127 | // past, skip
128 | if (!isRestaurant && !wasRestaurantBefore) {
129 | continue;
130 | }
131 |
132 | // Print an empty line between different nodes
133 | if (lastNode != null && !isUpdate) {
134 | System.out.println();
135 | }
136 |
137 | // Print node info if the restaurant in encountered the first
138 | // time, print changes on updates
139 | if (!isUpdate) {
140 | System.out.println(String.format(
141 | "id: %d, lat: %.6f, lon: %.6f, timestamp: %s",
142 | node.getId(), node.getLatitude(),
143 | node.getLongitude(), pattern.print(timestamp)));
144 | System.out.println(String.format("tags: %s",
145 | OsmModelUtil.getTagsAsList(node)));
146 | } else {
147 | System.out.println(String.format("upate on: %s",
148 | pattern.print(timestamp)));
149 | printChangesInPosition(node, lastNode);
150 | printChangesInTags(currentTags, lastTags);
151 | }
152 | }
153 | }
154 | }
155 |
156 | private static boolean isRestaurant(Map currentTags)
157 | {
158 | String amenity = currentTags.get("amenity");
159 | if (amenity == null) {
160 | return false;
161 | }
162 | return amenity.equals("restaurant");
163 | }
164 |
165 | private static void printChangesInPosition(OsmNode node, OsmNode lastNode)
166 | {
167 | if (node.getLatitude() != lastNode.getLatitude()
168 | || node.getLongitude() != lastNode.getLongitude()) {
169 | System.out.println(String.format(" position: lat: %.6f, lon: %.6f",
170 | node.getLatitude(), node.getLongitude()));
171 | }
172 | }
173 |
174 | private static void printChangesInTags(Map current,
175 | Map old)
176 | {
177 | SetView onlyCurrent = Sets.difference(current.keySet(),
178 | old.keySet());
179 | SetView onlyOld = Sets.difference(old.keySet(),
180 | current.keySet());
181 | SetView both = Sets.intersection(current.keySet(),
182 | old.keySet());
183 |
184 | for (String key : onlyOld) {
185 | System.out.println(
186 | String.format(" rem tag '%s:%s'", key, old.get(key)));
187 | }
188 |
189 | for (String key : onlyCurrent) {
190 | System.out.println(
191 | String.format(" add tag '%s:%s'", key, current.get(key)));
192 | }
193 |
194 | for (String key : both) {
195 | if (!current.get(key).equals(old.get(key))) {
196 | System.out.println(
197 | String.format(" update tag '%s': '%s' -> '%s'", key,
198 | old.get(key), current.get(key)));
199 | }
200 | }
201 | }
202 |
203 | }
204 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/history/HistoryVisibilityStats.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.history;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 |
23 | import org.apache.hc.client5.http.classic.methods.HttpGet;
24 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
25 | import org.apache.hc.client5.http.protocol.HttpClientContext;
26 | import org.apache.hc.core5.http.HttpStatus;
27 |
28 | import com.google.common.collect.HashMultiset;
29 | import com.google.common.collect.Multiset;
30 |
31 | import de.topobyte.osm4j.core.access.OsmIterator;
32 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
33 | import de.topobyte.osm4j.core.model.iface.EntityType;
34 | import de.topobyte.osm4j.core.model.iface.OsmMetadata;
35 | import de.topobyte.osm4j.pbf.seq.PbfIterator;
36 |
37 | public class HistoryVisibilityStats
38 | {
39 |
40 | public static void main(String[] args) throws IOException
41 | {
42 | // Define a URL to retrieve some data
43 | String url = "https://osm-internal.download.geofabrik.de/europe/germany/bremen-internal.osh.pbf";
44 |
45 | CloseableHttpClient client = GeofabrikUtils.createClientWithCookie();
46 |
47 | HttpClientContext context = HttpClientContext.create();
48 | HttpGet request = new HttpGet(url);
49 |
50 | client.execute(request, context, response -> {
51 | if (response.getCode() == HttpStatus.SC_OK) {
52 | InputStream input = response.getEntity().getContent();
53 | process(input);
54 | } else {
55 | System.out.println(
56 | "Accessing the history file was not successful");
57 | }
58 | return null;
59 | });
60 | }
61 |
62 | private static void process(InputStream input)
63 | {
64 | // Create an iterator for PBF data
65 | OsmIterator iterator = new PbfIterator(input, true);
66 |
67 | Multiset countVisible = HashMultiset.create();
68 | Multiset countInvisible = HashMultiset.create();
69 |
70 | // Iterate all elements
71 | for (EntityContainer container : iterator) {
72 |
73 | OsmMetadata metadata = container.getEntity().getMetadata();
74 |
75 | if (metadata.isVisible()) {
76 | countVisible.add(container.getType());
77 | } else {
78 | countInvisible.add(container.getType());
79 | }
80 | }
81 |
82 | // Print info about visibility statistics
83 | System.out.println(String.format("nodes: %d visible, %d invisible",
84 | countVisible.count(EntityType.Node),
85 | countInvisible.count(EntityType.Node)));
86 | System.out.println(String.format("ways: %d visible, %d invisible",
87 | countVisible.count(EntityType.Way),
88 | countInvisible.count(EntityType.Way)));
89 | System.out.println(String.format("relations: %d visible, %d invisible",
90 | countVisible.count(EntityType.Relation),
91 | countInvisible.count(EntityType.Relation)));
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/misc/ListRestaurantsInHavana.java:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.misc;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.nio.file.Files;
23 | import java.nio.file.Path;
24 | import java.nio.file.Paths;
25 | import java.util.Map;
26 |
27 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
28 | import de.topobyte.osm4j.core.model.iface.EntityType;
29 | import de.topobyte.osm4j.core.model.iface.OsmEntity;
30 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
31 | import de.topobyte.osm4j.pbf.seq.PbfIterator;
32 |
33 | public class ListRestaurantsInHavana
34 | {
35 |
36 | public static void main(String[] args) throws IOException
37 | {
38 | Path path = Paths.get("/tmp/havana-latest.pbf");
39 | InputStream input = Files.newInputStream(path);
40 | PbfIterator iterator = new PbfIterator(input, false);
41 |
42 | int n = 0;
43 | int w = 0;
44 | int r = 0;
45 | int noName = 0;
46 |
47 | for (EntityContainer object : iterator) {
48 | OsmEntity entity = object.getEntity();
49 | Map tags = OsmModelUtil.getTagsAsMap(entity);
50 | String amenity = tags.get("amenity");
51 | if ("restaurant".equals(amenity)) {
52 | String name = tags.get("name");
53 | if (name == null) {
54 | noName++;
55 | } else {
56 | System.out.println(name);
57 | }
58 | if (object.getType() == EntityType.Node) {
59 | n++;
60 | } else if (object.getType() == EntityType.Way) {
61 | w++;
62 | } else if (object.getType() == EntityType.Relation) {
63 | r++;
64 | }
65 | }
66 | }
67 |
68 | System.out.println("-Summary-");
69 | System.out.println(
70 | String.format("nodes: %d, ways: %d, relations: %d", n, w, r));
71 | System.out.println(String.format("no name: %d", noName));
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/CountingBusinesses.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.Map;
24 |
25 | import de.topobyte.osm4j.core.access.OsmIterator;
26 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
27 | import de.topobyte.osm4j.core.model.iface.EntityType;
28 | import de.topobyte.osm4j.core.model.iface.OsmNode;
29 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
30 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
31 |
32 | public class CountingBusinesses
33 | {
34 |
35 | public static void main(String[] args) throws IOException
36 | {
37 | // Define a query to retrieve some data
38 | String query = "http://www.overpass-api.de/api/xapi?*[bbox="
39 | + "13.465661,52.504055,13.469817,52.506204]";
40 |
41 | // Open a stream
42 | InputStream input = new URL(query).openStream();
43 |
44 | // Create an iterator for XML data
45 | OsmIterator iterator = new OsmXmlIterator(input, false);
46 |
47 | // Initialize the counters
48 | int numRestaurants = 0;
49 | int numCafes = 0;
50 | int numPubs = 0;
51 |
52 | // Iterate objects, ignore non-node objects
53 | for (EntityContainer container : iterator) {
54 | if (container.getType() == EntityType.Node) {
55 | OsmNode node = (OsmNode) container.getEntity();
56 |
57 | // Get the node's tags as a map
58 | Map tags = OsmModelUtil.getTagsAsMap(node);
59 |
60 | // Get the value for the 'amenity' key
61 | String amenity = tags.get("amenity");
62 |
63 | // Ignore nodes without such a tag
64 | if (amenity == null) {
65 | continue;
66 | }
67 |
68 | // Increment counters depending on the type
69 | if (amenity.equals("restaurant")) {
70 | numRestaurants++;
71 | } else if (amenity.equals("cafe")) {
72 | numCafes++;
73 | } else if (amenity.equals("pub")) {
74 | numPubs++;
75 | }
76 | }
77 | }
78 |
79 | // Print the results
80 | System.out.println("restaurants: " + numRestaurants);
81 | System.out.println("cafes: " + numCafes);
82 | System.out.println("pubs: " + numPubs);
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/CountingElements.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 |
24 | import de.topobyte.osm4j.core.access.OsmIterator;
25 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
26 | import de.topobyte.osm4j.core.model.iface.EntityType;
27 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
28 |
29 | public class CountingElements
30 | {
31 |
32 | public static void main(String[] args) throws IOException
33 | {
34 | // Define a query to retrieve some data
35 | String query = "http://www.overpass-api.de/api/xapi?*[bbox="
36 | + "13.465661,52.504055,13.469817,52.506204]";
37 |
38 | // Open a stream
39 | InputStream input = new URL(query).openStream();
40 |
41 | // Create an iterator for XML data
42 | OsmIterator iterator = new OsmXmlIterator(input, false);
43 |
44 | // Initialize some counters
45 | int numNodes = 0;
46 | int numWays = 0;
47 | int numRelations = 0;
48 |
49 | // Iterate elements and increment our counters
50 | // depending on the type of element
51 | for (EntityContainer container : iterator) {
52 | if (container.getType() == EntityType.Node) {
53 | numNodes++;
54 | } else if (container.getType() == EntityType.Way) {
55 | numWays++;
56 | } else if (container.getType() == EntityType.Relation) {
57 | numRelations++;
58 | }
59 | }
60 |
61 | // Print the results
62 | System.out.println("nodes: " + numNodes);
63 | System.out.println("ways: " + numWays);
64 | System.out.println("relations: " + numRelations);
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/CountingElements2.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 |
24 | import de.topobyte.osm4j.core.access.OsmIterator;
25 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
26 | import de.topobyte.osm4j.core.model.iface.EntityType;
27 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
28 |
29 | public class CountingElements2
30 | {
31 |
32 | public static void main(String[] args) throws IOException
33 | {
34 | // Define a query to retrieve some data
35 | String query = "http://www.overpass-api.de/api/xapi?*[bbox="
36 | + "13.465661,52.504055,13.469817,52.506204]";
37 |
38 | // Open a stream
39 | InputStream input = new URL(query).openStream();
40 |
41 | // Create an iterator for XML data
42 | OsmIterator iterator = new OsmXmlIterator(input, false);
43 |
44 | // Initialize some counters
45 | int numNodes = 0;
46 | int numWays = 0;
47 | int numRelations = 0;
48 |
49 | // Iterate elements and increment our counters
50 | // depending on the type of element
51 | while (iterator.hasNext()) {
52 | EntityContainer container = iterator.next();
53 | if (container.getType() == EntityType.Node) {
54 | numNodes++;
55 | } else if (container.getType() == EntityType.Way) {
56 | numWays++;
57 | } else if (container.getType() == EntityType.Relation) {
58 | numRelations++;
59 | }
60 | }
61 |
62 | // Print the results
63 | System.out.println("nodes: " + numNodes);
64 | System.out.println("ways: " + numWays);
65 | System.out.println("relations: " + numRelations);
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/CountingElements3.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 |
24 | import de.topobyte.osm4j.core.access.DefaultOsmHandler;
25 | import de.topobyte.osm4j.core.access.OsmInputException;
26 | import de.topobyte.osm4j.core.access.OsmReader;
27 | import de.topobyte.osm4j.core.model.iface.OsmNode;
28 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
29 | import de.topobyte.osm4j.core.model.iface.OsmWay;
30 | import de.topobyte.osm4j.xml.dynsax.OsmXmlReader;
31 |
32 | public class CountingElements3
33 | {
34 |
35 | public static void main(String[] args) throws IOException, OsmInputException
36 | {
37 | // Define a query to retrieve some data
38 | String query = "http://www.overpass-api.de/api/xapi?*[bbox="
39 | + "13.465661,52.504055,13.469817,52.506204]";
40 |
41 | // Open a stream
42 | InputStream input = new URL(query).openStream();
43 |
44 | // Create a reader for XML data
45 | OsmReader reader = new OsmXmlReader(input, false);
46 |
47 | // Create our counter and set it as a handler for the reader
48 | Counter counter = new Counter();
49 | reader.setHandler(counter);
50 |
51 | // Let the reader parse the data
52 | reader.read();
53 |
54 | // Print the results
55 | System.out.println("nodes: " + counter.numNodes);
56 | System.out.println("ways: " + counter.numWays);
57 | System.out.println("relations: " + counter.numRelations);
58 | }
59 |
60 | private static class Counter extends DefaultOsmHandler
61 | {
62 |
63 | int numNodes = 0;
64 | int numWays = 0;
65 | int numRelations = 0;
66 |
67 | @Override
68 | public void handle(OsmNode node)
69 | {
70 | numNodes++;
71 | }
72 |
73 | @Override
74 | public void handle(OsmWay way)
75 | {
76 | numWays++;
77 | }
78 |
79 | @Override
80 | public void handle(OsmRelation relation)
81 | {
82 | numRelations++;
83 | }
84 |
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/HelloWorld.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 |
24 | import de.topobyte.osm4j.core.access.OsmIterator;
25 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
26 | import de.topobyte.osm4j.core.model.iface.EntityType;
27 | import de.topobyte.osm4j.core.model.iface.OsmNode;
28 | import de.topobyte.osm4j.core.model.iface.OsmTag;
29 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
30 |
31 | public class HelloWorld
32 | {
33 |
34 | public static void main(String[] args) throws IOException
35 | {
36 | // Define a query to retrieve some data
37 | String query = "http://osmtestdata.topobyte.de/big-ben.osm";
38 |
39 | // Open a stream
40 | InputStream input = new URL(query).openStream();
41 |
42 | // Create an iterator for XML data
43 | OsmIterator iterator = new OsmXmlIterator(input, false);
44 |
45 | // Iterate all elements
46 | for (EntityContainer container : iterator) {
47 |
48 | // Check if the element is a node
49 | if (container.getType() == EntityType.Node) {
50 |
51 | // Cast the entity to OsmNode
52 | OsmNode node = (OsmNode) container.getEntity();
53 |
54 | // Print basic information
55 | System.out.println("id: " + node.getId());
56 | System.out.println("latitude: " + node.getLatitude());
57 | System.out.println("longitude: " + node.getLongitude());
58 |
59 | // Also print all tags
60 | System.out.println("tags:");
61 | for (int i = 0; i < node.getNumberOfTags(); i++) {
62 | OsmTag tag = node.getTag(i);
63 | System.out.println(tag.getKey() + " = " + tag.getValue());
64 | }
65 | }
66 | }
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/MapRendering.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial;
19 |
20 | import java.awt.BasicStroke;
21 | import java.awt.Color;
22 | import java.awt.Dimension;
23 | import java.awt.FontMetrics;
24 | import java.awt.Graphics;
25 | import java.awt.Graphics2D;
26 | import java.awt.RenderingHints;
27 | import java.awt.Shape;
28 | import java.awt.event.ComponentAdapter;
29 | import java.awt.event.ComponentEvent;
30 | import java.awt.geom.AffineTransform;
31 | import java.awt.geom.Path2D;
32 | import java.io.IOException;
33 | import java.io.InputStream;
34 | import java.net.URL;
35 | import java.util.ArrayList;
36 | import java.util.Arrays;
37 | import java.util.Collection;
38 | import java.util.HashMap;
39 | import java.util.HashSet;
40 | import java.util.List;
41 | import java.util.Map;
42 | import java.util.Set;
43 |
44 | import javax.swing.JFrame;
45 | import javax.swing.JPanel;
46 |
47 | import org.locationtech.jts.geom.Coordinate;
48 | import org.locationtech.jts.geom.Geometry;
49 | import org.locationtech.jts.geom.GeometryFactory;
50 | import org.locationtech.jts.geom.LineString;
51 | import org.locationtech.jts.geom.MultiPolygon;
52 |
53 | import de.topobyte.adt.geo.BBox;
54 | import de.topobyte.jgs.transform.CoordinateTransformer;
55 | import de.topobyte.jts2awt.Jts2Awt;
56 | import de.topobyte.mercator.image.MercatorImage;
57 | import de.topobyte.osm4j.core.access.OsmInputException;
58 | import de.topobyte.osm4j.core.access.OsmReader;
59 | import de.topobyte.osm4j.core.dataset.InMemoryMapDataSet;
60 | import de.topobyte.osm4j.core.dataset.MapDataSetLoader;
61 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
62 | import de.topobyte.osm4j.core.model.iface.OsmWay;
63 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
64 | import de.topobyte.osm4j.core.resolve.EntityFinder;
65 | import de.topobyte.osm4j.core.resolve.EntityFinders;
66 | import de.topobyte.osm4j.core.resolve.EntityNotFoundException;
67 | import de.topobyte.osm4j.core.resolve.EntityNotFoundStrategy;
68 | import de.topobyte.osm4j.geometry.RegionBuilder;
69 | import de.topobyte.osm4j.geometry.RegionBuilderResult;
70 | import de.topobyte.osm4j.geometry.WayBuilder;
71 | import de.topobyte.osm4j.geometry.WayBuilderResult;
72 | import de.topobyte.osm4j.xml.dynsax.OsmXmlReader;
73 |
74 | public class MapRendering extends JPanel
75 | {
76 |
77 | private static final long serialVersionUID = 1L;
78 |
79 | public static void main(String[] args) throws IOException, OsmInputException
80 | {
81 | // This is the region we would like to render
82 | BBox bbox = new BBox(13.45546, 52.51229, 13.46642, 52.50761);
83 | int width = 800;
84 | int height = 600;
85 |
86 | // Define a query to retrieve some data
87 | String queryTemplate = "http://overpass-api.de/api/interpreter?data=(node(%f,%f,%f,%f);<;>;);out;";
88 | String query = String.format(queryTemplate, bbox.getLat2(),
89 | bbox.getLon1(), bbox.getLat1(), bbox.getLon2());
90 |
91 | // Open a stream
92 | InputStream input = new URL(query).openStream();
93 |
94 | // Create a reader and read all data into a data set
95 | OsmReader reader = new OsmXmlReader(input, false);
96 | InMemoryMapDataSet data = MapDataSetLoader.read(reader, true, true,
97 | true);
98 |
99 | // The MercatorImage class knows how to transform input coordinates to
100 | // the selected region selected via bounding box
101 | MercatorImage mapImage = new MercatorImage(bbox, width, height);
102 |
103 | // Instantiate our class
104 | MapRendering panel = new MapRendering(bbox, mapImage, data);
105 | panel.setPreferredSize(new Dimension(width, height));
106 |
107 | // Setup a frame to show our panel
108 | JFrame frame = new JFrame("Map rendering");
109 | frame.setContentPane(panel);
110 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
111 | frame.pack();
112 | frame.setVisible(true);
113 | }
114 |
115 | // Some fields that define the map colors and street line widths
116 | private Color cBackground = new Color(0xEEEEEE);
117 | private Color cBBox = Color.BLUE;
118 | private Color cStreetForeground = Color.WHITE;
119 | private Color cStreetBackground = new Color(0xDDDDDD);
120 | private Color cStreetText = Color.BLACK;
121 | private Color cBuildings = new Color(0xFFC2C2);
122 |
123 | private int widthStreetBackground = 14;
124 | private int widthStreetForeground = 10;
125 |
126 | // This is a set of values for the 'highway' key of ways that we will render
127 | // as streets
128 | private Set validHighways = new HashSet<>(
129 | Arrays.asList(new String[] { "primary", "secondary", "tertiary",
130 | "residential", "living_street" }));
131 |
132 | // This will be used to map geometry coordinates to screen coordinates
133 | private MercatorImage mercatorImage;
134 |
135 | // We need to keep the reference to the bounding box, so that we can create
136 | // a new MercatorImage if the size of our panel changes
137 | private BBox bbox;
138 |
139 | // The data set will be used as entity provider when building geometries
140 | private InMemoryMapDataSet data;
141 |
142 | // We build the geometries to be rendered during construction and store them
143 | // in these fields so that we don't have to recompute everything when
144 | // rendering.
145 | private List buildings = new ArrayList<>();
146 | private List streets = new ArrayList<>();
147 | private Map names = new HashMap<>();
148 |
149 | public MapRendering(BBox bbox, MercatorImage mercatorImage,
150 | InMemoryMapDataSet data)
151 | {
152 | this.bbox = bbox;
153 | this.mercatorImage = mercatorImage;
154 | this.data = data;
155 |
156 | // When the panel's size changes, define a new MercatorImage and trigger
157 | // a repaint on our panel
158 | addComponentListener(new ComponentAdapter() {
159 |
160 | @Override
161 | public void componentResized(ComponentEvent e)
162 | {
163 | refreshMercatorImage();
164 | repaint();
165 | }
166 |
167 | });
168 |
169 | buildRenderingData();
170 | }
171 |
172 | private void buildRenderingData()
173 | {
174 | // We create building geometries from relations and ways. Ways that are
175 | // part of multipolygon buildings may be tagged as buildings themselves,
176 | // however rendering them independently will fill the polygon holes they
177 | // are cutting out of the relations. Hence we store the ways found in
178 | // building relations to skip them later on when working on the ways.
179 | Set buildingRelationWays = new HashSet<>();
180 | // We use this to find all way members of relations.
181 | EntityFinder wayFinder = EntityFinders.create(data,
182 | EntityNotFoundStrategy.IGNORE);
183 |
184 | // Collect buildings from relation areas...
185 | for (OsmRelation relation : data.getRelations().valueCollection()) {
186 | Map tags = OsmModelUtil.getTagsAsMap(relation);
187 | if (tags.containsKey("building")) {
188 | MultiPolygon area = getPolygon(relation);
189 | if (area != null) {
190 | buildings.add(area);
191 | }
192 | try {
193 | wayFinder.findMemberWays(relation, buildingRelationWays);
194 | } catch (EntityNotFoundException e) {
195 | // cannot happen (IGNORE strategy)
196 | }
197 | }
198 | }
199 | // ... and also from way areas
200 | for (OsmWay way : data.getWays().valueCollection()) {
201 | if (buildingRelationWays.contains(way)) {
202 | continue;
203 | }
204 | Map tags = OsmModelUtil.getTagsAsMap(way);
205 | if (tags.containsKey("building")) {
206 | MultiPolygon area = getPolygon(way);
207 | if (area != null) {
208 | buildings.add(area);
209 | }
210 | }
211 | }
212 |
213 | // Collect streets
214 | for (OsmWay way : data.getWays().valueCollection()) {
215 | Map tags = OsmModelUtil.getTagsAsMap(way);
216 |
217 | String highway = tags.get("highway");
218 | if (highway == null) {
219 | continue;
220 | }
221 |
222 | Collection paths = getLine(way);
223 |
224 | if (!validHighways.contains(highway)) {
225 | continue;
226 | }
227 |
228 | // Okay, this is a valid street
229 | for (LineString path : paths) {
230 | streets.add(path);
231 | }
232 |
233 | // If it has a name, store it for labeling
234 | String name = tags.get("name");
235 | if (name == null) {
236 | continue;
237 | }
238 | for (LineString path : paths) {
239 | names.put(path, name);
240 | }
241 | }
242 | }
243 |
244 | public void refreshMercatorImage()
245 | {
246 | mercatorImage = new MercatorImage(bbox, getWidth(), getHeight());
247 | }
248 |
249 | @Override
250 | protected void paintComponent(Graphics graphics)
251 | {
252 | super.paintComponent(graphics);
253 | Graphics2D g = (Graphics2D) graphics;
254 | g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
255 | RenderingHints.VALUE_ANTIALIAS_ON);
256 |
257 | // Fill the background
258 | g.setColor(cBackground);
259 | g.fillRect(0, 0, getWidth(), getHeight());
260 |
261 | // First render buildings
262 | g.setColor(cBuildings);
263 | for (Geometry building : buildings) {
264 | Shape polygon = Jts2Awt.toShape(building, mercatorImage);
265 | g.fill(polygon);
266 | }
267 |
268 | // First pass of street rendering: outlines
269 | g.setColor(cStreetBackground);
270 | g.setStroke(new BasicStroke(widthStreetBackground,
271 | BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
272 |
273 | for (LineString street : streets) {
274 | Path2D path = Jts2Awt.getPath(street, mercatorImage);
275 | g.draw(path);
276 | }
277 |
278 | // Second pass of street rendering: foreground
279 | g.setColor(cStreetForeground);
280 | g.setStroke(new BasicStroke(widthStreetForeground,
281 | BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
282 |
283 | for (LineString street : streets) {
284 | Path2D path = Jts2Awt.getPath(street, mercatorImage);
285 | g.draw(path);
286 | }
287 |
288 | // Now add labels where possible
289 | g.setFont(g.getFont().deriveFont(12f));
290 | g.setColor(cStreetText);
291 |
292 | for (LineString street : streets) {
293 | String name = names.get(street);
294 | if (name == null) {
295 | continue;
296 | }
297 | paintStreetLabel(g, street, name, mercatorImage);
298 | }
299 |
300 | // Also draw a rectangle around the query bounding box
301 | Geometry queryBox = new GeometryFactory().toGeometry(bbox.toEnvelope());
302 | Shape shape = Jts2Awt.toShape(queryBox, mercatorImage);
303 | g.setColor(cBBox);
304 | g.setStroke(new BasicStroke(2));
305 | g.draw(shape);
306 | }
307 |
308 | private void paintStreetLabel(Graphics2D g, LineString street, String name,
309 | CoordinateTransformer t)
310 | {
311 | // We will need this to measure the length of street names
312 | FontMetrics metrics = g.getFontMetrics();
313 |
314 | // For each segment
315 | for (int i = 1; i < street.getNumPoints(); i++) {
316 |
317 | // Segment is from c to d (WGS84 coordinates)
318 | Coordinate c = street.getCoordinateN(i - 1);
319 | Coordinate d = street.getCoordinateN(i);
320 |
321 | // Map coordinates to screen coordinates
322 | double cx = t.getX(c.x);
323 | double cy = t.getY(c.y);
324 | double dx = t.getX(d.x);
325 | double dy = t.getY(d.y);
326 |
327 | // Determine the length of the segment on the screen
328 | double len = Math
329 | .sqrt((dx - cx) * (dx - cx) + (dy - cy) * (dy - cy));
330 |
331 | // And also the length of the rendered street name
332 | int textLength = metrics.stringWidth(name);
333 |
334 | // Render only if there is enough space
335 | if (len <= textLength) {
336 | continue;
337 | }
338 |
339 | // We're going to modify the Graphics2D's transformation object to
340 | // render the text rotated and positioned, so we need to backup the
341 | // current transform object
342 | AffineTransform backup = g.getTransform();
343 |
344 | // We center the text on the segment so we calculate the offset
345 | // depending on the actual length of the text
346 | double offset = (len - textLength) / 2;
347 |
348 | // Define how to render text using transformations
349 | g.translate(cx, cy);
350 | g.rotate(Math.atan2(dy - cy, dx - cx));
351 | g.translate(offset, 4);
352 |
353 | // Draw!
354 | g.drawString(name, 0, 0);
355 |
356 | // Undo our transformation
357 | g.setTransform(backup);
358 | }
359 | }
360 |
361 | private WayBuilder wayBuilder = new WayBuilder();
362 | private RegionBuilder regionBuilder = new RegionBuilder();
363 |
364 | private Collection getLine(OsmWay way)
365 | {
366 | List results = new ArrayList<>();
367 | try {
368 | WayBuilderResult lines = wayBuilder.build(way, data);
369 | results.addAll(lines.getLineStrings());
370 | if (lines.getLinearRing() != null) {
371 | results.add(lines.getLinearRing());
372 | }
373 | } catch (EntityNotFoundException e) {
374 | // ignore
375 | }
376 | return results;
377 | }
378 |
379 | private MultiPolygon getPolygon(OsmWay way)
380 | {
381 | try {
382 | RegionBuilderResult region = regionBuilder.build(way, data);
383 | return region.getMultiPolygon();
384 | } catch (EntityNotFoundException e) {
385 | return null;
386 | }
387 | }
388 |
389 | private MultiPolygon getPolygon(OsmRelation relation)
390 | {
391 | try {
392 | RegionBuilderResult region = regionBuilder.build(relation, data);
393 | return region.getMultiPolygon();
394 | } catch (EntityNotFoundException e) {
395 | return null;
396 | }
397 | }
398 |
399 | }
400 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/OverpassToPbf.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial;
19 |
20 | import java.io.FileOutputStream;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.io.OutputStream;
24 | import java.net.URL;
25 |
26 | import de.topobyte.osm4j.core.access.OsmIterator;
27 | import de.topobyte.osm4j.core.access.OsmOutputStream;
28 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
29 | import de.topobyte.osm4j.core.model.iface.OsmNode;
30 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
31 | import de.topobyte.osm4j.core.model.iface.OsmWay;
32 | import de.topobyte.osm4j.pbf.seq.PbfWriter;
33 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
34 |
35 | public class OverpassToPbf
36 | {
37 |
38 | public static void main(String[] args) throws IOException
39 | {
40 | // Define a query to retrieve some data
41 | String query = "http://www.overpass-api.de/api/xapi?*[bbox="
42 | + "13.465661,52.504055,13.469817,52.506204]";
43 |
44 | // Open a stream
45 | InputStream input = new URL(query).openStream();
46 |
47 | // Create an iterator for XML data
48 | OsmIterator iterator = new OsmXmlIterator(input, true);
49 |
50 | // Create an output stream
51 | OutputStream output = new FileOutputStream("/tmp/bbox.pbf");
52 | OsmOutputStream osmOutput = new PbfWriter(output, true);
53 |
54 | // Iterate objects and copy them to the output
55 | for (EntityContainer container : iterator) {
56 | switch (container.getType()) {
57 | default:
58 | case Node:
59 | osmOutput.write((OsmNode) container.getEntity());
60 | break;
61 | case Way:
62 | osmOutput.write((OsmWay) container.getEntity());
63 | break;
64 | case Relation:
65 | osmOutput.write((OsmRelation) container.getEntity());
66 | break;
67 | }
68 | }
69 |
70 | // Close output
71 | osmOutput.complete();
72 | output.close();
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/PbfToXml.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial;
19 |
20 | import java.io.FileInputStream;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 |
24 | import de.topobyte.osm4j.core.access.OsmIterator;
25 | import de.topobyte.osm4j.core.access.OsmOutputStream;
26 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
27 | import de.topobyte.osm4j.core.model.iface.OsmNode;
28 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
29 | import de.topobyte.osm4j.core.model.iface.OsmWay;
30 | import de.topobyte.osm4j.pbf.seq.PbfIterator;
31 | import de.topobyte.osm4j.xml.output.OsmXmlOutputStream;
32 |
33 | public class PbfToXml
34 | {
35 |
36 | public static void main(String[] args) throws IOException
37 | {
38 | // Open a file as input
39 | InputStream input = new FileInputStream("/tmp/bbox.pbf");
40 |
41 | // Create an iterator for PBF data
42 | OsmIterator iterator = new PbfIterator(input, true);
43 |
44 | // Create an output stream
45 | OsmOutputStream osmOutput = new OsmXmlOutputStream(System.out, true);
46 |
47 | // Iterate objects and copy them to the output
48 | for (EntityContainer container : iterator) {
49 | switch (container.getType()) {
50 | default:
51 | case Node:
52 | osmOutput.write((OsmNode) container.getEntity());
53 | break;
54 | case Way:
55 | osmOutput.write((OsmWay) container.getEntity());
56 | break;
57 | case Relation:
58 | osmOutput.write((OsmRelation) container.getEntity());
59 | break;
60 | }
61 | }
62 |
63 | // Close output
64 | osmOutput.complete();
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/geometry/BouroughBboxesBerlin.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial.geometry;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.ArrayList;
24 | import java.util.HashMap;
25 | import java.util.List;
26 | import java.util.Map;
27 |
28 | import org.locationtech.jts.geom.Envelope;
29 | import org.locationtech.jts.geom.MultiPolygon;
30 |
31 | import de.topobyte.adt.geo.BBox;
32 | import de.topobyte.osm4j.core.access.OsmIterator;
33 | import de.topobyte.osm4j.core.dataset.InMemoryMapDataSet;
34 | import de.topobyte.osm4j.core.dataset.MapDataSetLoader;
35 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
36 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
37 | import de.topobyte.osm4j.core.resolve.EntityNotFoundException;
38 | import de.topobyte.osm4j.geometry.RegionBuilder;
39 | import de.topobyte.osm4j.geometry.RegionBuilderResult;
40 | import de.topobyte.osm4j.tbo.access.TboIterator;
41 |
42 | public class BouroughBboxesBerlin
43 | {
44 |
45 | public static void main(String[] args) throws IOException
46 | {
47 | RegionBuilder regionBuilder = new RegionBuilder();
48 |
49 | // This is where we get the boroughs from
50 | String urlBoroughs = "http://osmtestdata.topobyte.de/Berlin.admin10.all.tbo";
51 |
52 | // Read boroughs
53 | InputStream input = new URL(urlBoroughs).openStream();
54 | OsmIterator iterator = new TboIterator(input, true, false);
55 | InMemoryMapDataSet boroughsData = MapDataSetLoader.read(iterator, false,
56 | false, true);
57 | input.close();
58 |
59 | // Build borough polygons and map their names
60 | List boroughs = new ArrayList<>();
61 | Map names = new HashMap<>();
62 |
63 | for (OsmRelation relation : boroughsData.getRelations()
64 | .valueCollection()) {
65 | Map tags = OsmModelUtil.getTagsAsMap(relation);
66 | String name = tags.get("name");
67 | if (name == null) {
68 | continue;
69 | }
70 | try {
71 | RegionBuilderResult region = regionBuilder.build(relation,
72 | boroughsData);
73 | MultiPolygon polygon = region.getMultiPolygon();
74 | if (polygon.isEmpty()) {
75 | continue;
76 | }
77 | boroughs.add(polygon);
78 | names.put(polygon, name);
79 | } catch (EntityNotFoundException e) {
80 | System.out.println("Unable to build polygon: " + tags);
81 | }
82 | }
83 |
84 | // Calculate the bounding box and print info
85 | for (MultiPolygon borough : boroughs) {
86 | String name = names.get(borough);
87 | Envelope envelope = borough.getEnvelopeInternal();
88 | BBox bbox = new BBox(envelope);
89 | System.out.println(String.format("%s: %s", name, bbox.toString()));
90 | }
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/geometry/BuildPolygon1.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial.geometry;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | import org.locationtech.jts.geom.Geometry;
27 | import org.wololo.geojson.Feature;
28 | import org.wololo.jts2geojson.GeoJSONWriter;
29 |
30 | import com.slimjars.dist.gnu.trove.map.TLongObjectMap;
31 |
32 | import de.topobyte.osm4j.core.access.OsmIterator;
33 | import de.topobyte.osm4j.core.dataset.InMemoryMapDataSet;
34 | import de.topobyte.osm4j.core.dataset.MapDataSetLoader;
35 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
36 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
37 | import de.topobyte.osm4j.core.resolve.EntityNotFoundException;
38 | import de.topobyte.osm4j.geometry.GeometryBuilder;
39 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
40 |
41 | public class BuildPolygon1
42 | {
43 |
44 | public static void main(String[] args)
45 | throws IOException, EntityNotFoundException
46 | {
47 | // String query =
48 | // "http://overpass-api.de/api/interpreter?data=(rel(122895);>;);out;";
49 | String query = "http://osmtestdata.topobyte.de/relation-122895.osm";
50 |
51 | // Open a stream
52 | InputStream input = new URL(query).openStream();
53 |
54 | OsmIterator iterator = new OsmXmlIterator(input, false);
55 | InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false,
56 | true);
57 |
58 | TLongObjectMap relations = data.getRelations();
59 |
60 | if (relations.isEmpty()) {
61 | System.out.println("No relation found");
62 | return;
63 | }
64 |
65 | OsmRelation relation = relations.valueCollection().iterator().next();
66 |
67 | Geometry polygon = new GeometryBuilder().build(relation, data);
68 |
69 | Map tags = OsmModelUtil.getTagsAsMap(relation);
70 | Map properties = new HashMap<>();
71 | for (String key : tags.keySet()) {
72 | properties.put(key, tags.get(key));
73 | }
74 |
75 | GeoJSONWriter writer = new GeoJSONWriter();
76 | org.wololo.geojson.Geometry g = writer.write(polygon);
77 | Feature feature = new Feature(g, properties);
78 |
79 | String json = feature.toString();
80 |
81 | System.out.println(GeoJsonHelper.prettyPrintFeature(json));
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/geometry/BuildPolygon2.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial.geometry;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | import org.locationtech.jts.geom.Geometry;
27 | import org.wololo.geojson.Feature;
28 | import org.wololo.jts2geojson.GeoJSONWriter;
29 |
30 | import com.slimjars.dist.gnu.trove.map.TLongObjectMap;
31 |
32 | import de.topobyte.osm4j.core.access.OsmIterator;
33 | import de.topobyte.osm4j.core.dataset.InMemoryMapDataSet;
34 | import de.topobyte.osm4j.core.dataset.MapDataSetLoader;
35 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
36 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
37 | import de.topobyte.osm4j.core.resolve.EntityNotFoundException;
38 | import de.topobyte.osm4j.geometry.GeometryBuilder;
39 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
40 |
41 | public class BuildPolygon2
42 | {
43 |
44 | public static void main(String[] args)
45 | throws IOException, EntityNotFoundException
46 | {
47 | // String query =
48 | // "http://overpass-api.de/api/interpreter?data=(rel(16566);>;);out;";
49 | String query = "http://osmtestdata.topobyte.de/relation-16566.osm";
50 |
51 | // Open a stream
52 | InputStream input = new URL(query).openStream();
53 |
54 | OsmIterator iterator = new OsmXmlIterator(input, false);
55 | InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false,
56 | true);
57 |
58 | TLongObjectMap relations = data.getRelations();
59 |
60 | if (relations.isEmpty()) {
61 | System.out.println("No relation found");
62 | return;
63 | }
64 |
65 | OsmRelation relation = relations.valueCollection().iterator().next();
66 |
67 | Geometry polygon = new GeometryBuilder().build(relation, data);
68 |
69 | Map tags = OsmModelUtil.getTagsAsMap(relation);
70 | Map properties = new HashMap<>();
71 | for (String key : tags.keySet()) {
72 | properties.put(key, tags.get(key));
73 | }
74 |
75 | GeoJSONWriter writer = new GeoJSONWriter();
76 | org.wololo.geojson.Geometry g = writer.write(polygon);
77 | Feature feature = new Feature(g, properties);
78 |
79 | String json = feature.toString();
80 |
81 | System.out.println(GeoJsonHelper.prettyPrintFeature(json));
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/geometry/BuildWayPolygon.java:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial.geometry;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | import org.locationtech.jts.geom.Geometry;
27 | import org.wololo.geojson.Feature;
28 | import org.wololo.jts2geojson.GeoJSONWriter;
29 |
30 | import com.slimjars.dist.gnu.trove.map.TLongObjectMap;
31 |
32 | import de.topobyte.osm4j.core.access.OsmIterator;
33 | import de.topobyte.osm4j.core.dataset.InMemoryMapDataSet;
34 | import de.topobyte.osm4j.core.dataset.MapDataSetLoader;
35 | import de.topobyte.osm4j.core.model.iface.OsmWay;
36 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
37 | import de.topobyte.osm4j.core.resolve.EntityNotFoundException;
38 | import de.topobyte.osm4j.geometry.RegionBuilder;
39 | import de.topobyte.osm4j.geometry.RegionBuilderResult;
40 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
41 |
42 | public class BuildWayPolygon
43 | {
44 |
45 | public static void main(String[] args)
46 | throws IOException, EntityNotFoundException
47 | {
48 | String query = "http://overpass-api.de/api/interpreter?data=(way(477546559);>;);out;";
49 |
50 | // Open a stream
51 | InputStream input = new URL(query).openStream();
52 |
53 | OsmIterator iterator = new OsmXmlIterator(input, false);
54 | InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false,
55 | true);
56 |
57 | TLongObjectMap ways = data.getWays();
58 |
59 | if (ways.isEmpty()) {
60 | System.out.println("No way found");
61 | return;
62 | }
63 |
64 | OsmWay way = ways.valueCollection().iterator().next();
65 |
66 | RegionBuilder rb = new RegionBuilder();
67 | RegionBuilderResult result = rb.build(way, data);
68 | Geometry polygon = result.getMultiPolygon();
69 |
70 | Map tags = OsmModelUtil.getTagsAsMap(way);
71 | Map properties = new HashMap<>();
72 | for (String key : tags.keySet()) {
73 | properties.put(key, tags.get(key));
74 | }
75 |
76 | GeoJSONWriter writer = new GeoJSONWriter();
77 | org.wololo.geojson.Geometry g = writer.write(polygon);
78 | Feature feature = new Feature(g, properties);
79 |
80 | String json = feature.toString();
81 |
82 | System.out.println(GeoJsonHelper.prettyPrintFeature(json));
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/geometry/GeoJsonHelper.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial.geometry;
19 |
20 | import java.io.IOException;
21 |
22 | import com.fasterxml.jackson.core.JsonProcessingException;
23 | import com.fasterxml.jackson.databind.JsonNode;
24 | import com.fasterxml.jackson.databind.ObjectMapper;
25 | import com.fasterxml.jackson.databind.SerializationFeature;
26 | import com.fasterxml.jackson.databind.node.ObjectNode;
27 |
28 | public class GeoJsonHelper
29 | {
30 |
31 | public static String prettyPrintFeature(String featureJson)
32 | throws JsonProcessingException, IOException
33 | {
34 | ObjectMapper mapper = new ObjectMapper();
35 | mapper.enable(SerializationFeature.INDENT_OUTPUT);
36 |
37 | JsonNode tree = mapper.readTree(featureJson);
38 |
39 | JsonNode type = tree.get("type");
40 | JsonNode geometry = tree.get("geometry");
41 | JsonNode properties = tree.get("properties");
42 |
43 | ObjectNode root = mapper.createObjectNode();
44 | if (type != null) {
45 | root.set("type", type);
46 | }
47 | if (properties != null) {
48 | root.set("properties", properties);
49 | }
50 | if (geometry != null) {
51 | root.set("geometry", geometry);
52 | }
53 |
54 | return mapper.writeValueAsString(root);
55 | }
56 |
57 | public static String prettyPrintFeatureCollection(String featureJson)
58 | throws JsonProcessingException, IOException
59 | {
60 | ObjectMapper mapper = new ObjectMapper();
61 | mapper.enable(SerializationFeature.INDENT_OUTPUT);
62 |
63 | JsonNode tree = mapper.readTree(featureJson);
64 |
65 | JsonNode type = tree.get("type");
66 | JsonNode features = tree.get("features");
67 |
68 | ObjectNode root = mapper.createObjectNode();
69 | if (type != null) {
70 | root.set("type", type);
71 | }
72 | if (features != null) {
73 | root.set("features", features);
74 | }
75 |
76 | return mapper.writeValueAsString(root);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/geometry/PolygonBufferDifference.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial.geometry;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | import org.locationtech.jts.geom.Geometry;
27 | import org.locationtech.jts.geom.MultiPolygon;
28 | import org.wololo.geojson.Feature;
29 | import org.wololo.jts2geojson.GeoJSONWriter;
30 |
31 | import com.slimjars.dist.gnu.trove.map.TLongObjectMap;
32 |
33 | import de.topobyte.osm4j.core.access.OsmIterator;
34 | import de.topobyte.osm4j.core.dataset.InMemoryMapDataSet;
35 | import de.topobyte.osm4j.core.dataset.MapDataSetLoader;
36 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
37 | import de.topobyte.osm4j.core.resolve.EntityNotFoundException;
38 | import de.topobyte.osm4j.geometry.RegionBuilder;
39 | import de.topobyte.osm4j.geometry.RegionBuilderResult;
40 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
41 |
42 | public class PolygonBufferDifference
43 | {
44 |
45 | public static void main(String[] args)
46 | throws IOException, EntityNotFoundException
47 | {
48 | // String query =
49 | // "http://overpass-api.de/api/interpreter?data=(rel(16566);>;);out;";
50 | String query = "http://osmtestdata.topobyte.de/relation-16566.osm";
51 |
52 | // Open a stream
53 | InputStream input = new URL(query).openStream();
54 |
55 | OsmIterator iterator = new OsmXmlIterator(input, false);
56 | InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false,
57 | true);
58 |
59 | TLongObjectMap relations = data.getRelations();
60 |
61 | if (relations.isEmpty()) {
62 | System.out.println("No relation found");
63 | return;
64 | }
65 |
66 | OsmRelation relation = relations.valueCollection().iterator().next();
67 |
68 | // Build the polygon from the relation
69 | RegionBuilder regionBuilder = new RegionBuilder();
70 | RegionBuilderResult region = regionBuilder.build(relation, data);
71 | MultiPolygon polygon = region.getMultiPolygon();
72 |
73 | // Create a buffer
74 | Geometry buffer = polygon.buffer(0.005);
75 |
76 | // Compute the difference, buffer - polygon
77 | Geometry difference = buffer.difference(polygon);
78 |
79 | // GeoJSON output
80 | Map properties = new HashMap<>();
81 | GeoJSONWriter writer = new GeoJSONWriter();
82 | org.wololo.geojson.Geometry g = writer.write(difference);
83 | Feature feature = new Feature(g, properties);
84 |
85 | String json = feature.toString();
86 | System.out.println(GeoJsonHelper.prettyPrintFeature(json));
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/geometry/PolygonBufferNegative.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial.geometry;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | import org.locationtech.jts.geom.Geometry;
27 | import org.locationtech.jts.geom.GeometryCollection;
28 | import org.locationtech.jts.geom.GeometryFactory;
29 | import org.locationtech.jts.geom.MultiPolygon;
30 | import org.wololo.geojson.Feature;
31 | import org.wololo.jts2geojson.GeoJSONWriter;
32 |
33 | import com.slimjars.dist.gnu.trove.map.TLongObjectMap;
34 |
35 | import de.topobyte.osm4j.core.access.OsmIterator;
36 | import de.topobyte.osm4j.core.dataset.InMemoryMapDataSet;
37 | import de.topobyte.osm4j.core.dataset.MapDataSetLoader;
38 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
39 | import de.topobyte.osm4j.core.resolve.EntityNotFoundException;
40 | import de.topobyte.osm4j.geometry.RegionBuilder;
41 | import de.topobyte.osm4j.geometry.RegionBuilderResult;
42 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
43 |
44 | public class PolygonBufferNegative
45 | {
46 |
47 | public static void main(String[] args)
48 | throws IOException, EntityNotFoundException
49 | {
50 | // String query =
51 | // "http://overpass-api.de/api/interpreter?data=(rel(16566);>;);out;";
52 | String query = "http://osmtestdata.topobyte.de/relation-16566.osm";
53 |
54 | // Open a stream
55 | InputStream input = new URL(query).openStream();
56 |
57 | OsmIterator iterator = new OsmXmlIterator(input, false);
58 | InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false,
59 | true);
60 |
61 | TLongObjectMap relations = data.getRelations();
62 |
63 | if (relations.isEmpty()) {
64 | System.out.println("No relation found");
65 | return;
66 | }
67 |
68 | OsmRelation relation = relations.valueCollection().iterator().next();
69 |
70 | // Build the polygon from the relation
71 | RegionBuilder regionBuilder = new RegionBuilder();
72 | RegionBuilderResult region = regionBuilder.build(relation, data);
73 | MultiPolygon polygon = region.getMultiPolygon();
74 |
75 | // Create a buffer
76 | Geometry buffer = polygon.buffer(-0.005);
77 |
78 | // Combine the polygon and its buffer into a GeometryCollection
79 | GeometryCollection both = new GeometryFactory()
80 | .createGeometryCollection(new Geometry[] { polygon, buffer });
81 |
82 | // GeoJSON output
83 | Map properties = new HashMap<>();
84 | GeoJSONWriter writer = new GeoJSONWriter();
85 | org.wololo.geojson.Geometry g = writer.write(both);
86 | Feature feature = new Feature(g, properties);
87 |
88 | String json = feature.toString();
89 | System.out.println(GeoJsonHelper.prettyPrintFeature(json));
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/geometry/PolygonBufferPositive.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial.geometry;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | import org.locationtech.jts.geom.Geometry;
27 | import org.locationtech.jts.geom.GeometryFactory;
28 | import org.locationtech.jts.geom.MultiPolygon;
29 | import org.wololo.geojson.Feature;
30 | import org.wololo.jts2geojson.GeoJSONWriter;
31 |
32 | import com.slimjars.dist.gnu.trove.map.TLongObjectMap;
33 |
34 | import de.topobyte.osm4j.core.access.OsmIterator;
35 | import de.topobyte.osm4j.core.dataset.InMemoryMapDataSet;
36 | import de.topobyte.osm4j.core.dataset.MapDataSetLoader;
37 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
38 | import de.topobyte.osm4j.core.resolve.EntityNotFoundException;
39 | import de.topobyte.osm4j.geometry.RegionBuilder;
40 | import de.topobyte.osm4j.geometry.RegionBuilderResult;
41 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
42 |
43 | public class PolygonBufferPositive
44 | {
45 |
46 | public static void main(String[] args)
47 | throws IOException, EntityNotFoundException
48 | {
49 | // String query =
50 | // "http://overpass-api.de/api/interpreter?data=(rel(16566);>;);out;";
51 | String query = "http://osmtestdata.topobyte.de/relation-16566.osm";
52 |
53 | // Open a stream
54 | InputStream input = new URL(query).openStream();
55 |
56 | OsmIterator iterator = new OsmXmlIterator(input, false);
57 | InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false,
58 | true);
59 |
60 | TLongObjectMap relations = data.getRelations();
61 |
62 | if (relations.isEmpty()) {
63 | System.out.println("No relation found");
64 | return;
65 | }
66 |
67 | OsmRelation relation = relations.valueCollection().iterator().next();
68 |
69 | // Build the polygon from the relation
70 | RegionBuilder regionBuilder = new RegionBuilder();
71 | RegionBuilderResult region = regionBuilder.build(relation, data);
72 | MultiPolygon polygon = region.getMultiPolygon();
73 |
74 | // Create a buffer
75 | Geometry buffer = polygon.buffer(0.005);
76 |
77 | // Combine the polygon and its buffer into a GeometryCollection
78 | Geometry both = new GeometryFactory()
79 | .createGeometryCollection(new Geometry[] { polygon, buffer });
80 |
81 | // GeoJSON output
82 | Map properties = new HashMap<>();
83 | GeoJSONWriter writer = new GeoJSONWriter();
84 | org.wololo.geojson.Geometry g = writer.write(both);
85 | Feature feature = new Feature(g, properties);
86 |
87 | String json = feature.toString();
88 | System.out.println(GeoJsonHelper.prettyPrintFeature(json));
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/de/topobyte/osm4j/examples/tutorial/geometry/RestaurantDensityBerlin.java:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Sebastian Kuerten
2 | //
3 | // This file is part of osm4j.
4 | //
5 | // osm4j is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU Lesser General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License, or
8 | // (at your option) any later version.
9 | //
10 | // osm4j is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU Lesser General Public License for more details.
14 | //
15 | // You should have received a copy of the GNU Lesser General Public License
16 | // along with osm4j. If not, see .
17 |
18 | package de.topobyte.osm4j.examples.tutorial.geometry;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.ArrayList;
24 | import java.util.Collections;
25 | import java.util.HashMap;
26 | import java.util.List;
27 | import java.util.Map;
28 |
29 | import org.locationtech.jts.geom.Envelope;
30 | import org.locationtech.jts.geom.MultiPolygon;
31 | import org.locationtech.jts.geom.Point;
32 | import org.wololo.geojson.Feature;
33 | import org.wololo.geojson.FeatureCollection;
34 | import org.wololo.jts2geojson.GeoJSONWriter;
35 |
36 | import de.topobyte.adt.geo.BBox;
37 | import de.topobyte.osm4j.core.access.OsmIterator;
38 | import de.topobyte.osm4j.core.dataset.InMemoryMapDataSet;
39 | import de.topobyte.osm4j.core.dataset.MapDataSetLoader;
40 | import de.topobyte.osm4j.core.model.iface.EntityContainer;
41 | import de.topobyte.osm4j.core.model.iface.EntityType;
42 | import de.topobyte.osm4j.core.model.iface.OsmNode;
43 | import de.topobyte.osm4j.core.model.iface.OsmRelation;
44 | import de.topobyte.osm4j.core.model.util.OsmModelUtil;
45 | import de.topobyte.osm4j.core.resolve.EntityNotFoundException;
46 | import de.topobyte.osm4j.geometry.GeometryBuilder;
47 | import de.topobyte.osm4j.geometry.RegionBuilder;
48 | import de.topobyte.osm4j.geometry.RegionBuilderResult;
49 | import de.topobyte.osm4j.tbo.access.TboIterator;
50 | import de.topobyte.osm4j.xml.dynsax.OsmXmlIterator;
51 |
52 | public class RestaurantDensityBerlin
53 | {
54 |
55 | public static void main(String[] args) throws IOException
56 | {
57 | GeometryBuilder geometryBuilder = new GeometryBuilder();
58 | RegionBuilder regionBuilder = new RegionBuilder();
59 |
60 | // This is where we get the boroughs from
61 | String urlBoroughs = "http://osmtestdata.topobyte.de/Berlin.admin10.all.tbo";
62 |
63 | // This is where we will get the restaurants from
64 | String queryTemplate = "http://overpass-api.de/api/interpreter?data="
65 | + "node[\"amenity\"=\"restaurant\"](%f,%f,%f,%f);out;";
66 |
67 | // Read boroughs
68 | InputStream input = new URL(urlBoroughs).openStream();
69 | OsmIterator iterator = new TboIterator(input, true, false);
70 | InMemoryMapDataSet boroughsData = MapDataSetLoader.read(iterator, false,
71 | false, true);
72 | input.close();
73 |
74 | // Build borough polygons and map their names
75 | List boroughs = new ArrayList<>();
76 | Map names = new HashMap<>();
77 |
78 | for (OsmRelation relation : boroughsData.getRelations()
79 | .valueCollection()) {
80 | Map tags = OsmModelUtil.getTagsAsMap(relation);
81 | String name = tags.get("name");
82 | if (name == null) {
83 | continue;
84 | }
85 | try {
86 | RegionBuilderResult region = regionBuilder.build(relation,
87 | boroughsData);
88 | MultiPolygon polygon = region.getMultiPolygon();
89 | if (polygon.isEmpty()) {
90 | continue;
91 | }
92 | boroughs.add(polygon);
93 | names.put(polygon, name);
94 | } catch (EntityNotFoundException e) {
95 | System.out.println("Unable to build polygon: " + tags);
96 | }
97 | }
98 |
99 | // Calculate the bounding box for the data query
100 | Envelope env = boroughs.iterator().next().getEnvelopeInternal();
101 | for (MultiPolygon borough : boroughs) {
102 | env.expandToInclude(borough.getEnvelopeInternal());
103 | }
104 | BBox bbox = new BBox(env);
105 |
106 | // Define a query to retrieve some data
107 | String query = String.format(queryTemplate, bbox.getLat2(),
108 | bbox.getLon1(), bbox.getLat1(), bbox.getLon2());
109 |
110 | // Setup a map for counting values for each borough
111 | Map counters = new HashMap<>();
112 | for (MultiPolygon borough : boroughs) {
113 | counters.put(borough, 0);
114 | }
115 |
116 | // Analyze nodes
117 | input = new URL(query).openStream();
118 | iterator = new OsmXmlIterator(input, true);
119 | for (EntityContainer entity : iterator) {
120 | if (entity.getType() != EntityType.Node) {
121 | break;
122 | }
123 | OsmNode node = (OsmNode) entity.getEntity();
124 | Map tags = OsmModelUtil.getTagsAsMap(node);
125 |
126 | // This is not exactly necessary since the input will contain
127 | // restaurant nodes only anyway. Doing it anyway, your data soure
128 | // may be a different one.
129 | String amenity = tags.get("amenity");
130 | if (amenity == null || !amenity.equals("restaurant")) {
131 | continue;
132 | }
133 |
134 | // Determine which borough a restaurant is in, and increment the
135 | // counter
136 | Point point = geometryBuilder.build(node);
137 | for (MultiPolygon borough : boroughs) {
138 | if (borough.contains(point)) {
139 | counters.put(borough, counters.get(borough) + 1);
140 | }
141 | }
142 | }
143 |
144 | // Build density information
145 | Map densities = new HashMap<>();
146 | Map values = new HashMap<>();
147 |
148 | // Calculate density by dividing the counter by the borough's area
149 | for (MultiPolygon borough : boroughs) {
150 | int count = counters.get(borough);
151 | double density = count / borough.getArea();
152 | densities.put(borough, density);
153 | }
154 |
155 | // Determine a relative density scale from 0..1 depending on the minimum
156 | // and maximum density of all boroughs.
157 | // Then scale the relative density logarithmically to make it more
158 | // expressive.
159 | double min = Collections.min(densities.values());
160 | double max = Collections.max(densities.values());
161 | for (MultiPolygon borough : boroughs) {
162 | double density = densities.get(borough);
163 | double relative = (density - min) / (max - min);
164 |
165 | int exponent = 2;
166 | int upscale = (int) Math.pow(10, exponent) - 1;
167 | double value = Math.log10((1 + relative * upscale)) / exponent;
168 | values.put(borough, value);
169 | }
170 |
171 | // Build feature collection for output, assign colors ranging from
172 | // orange to blue
173 | Feature[] features = new Feature[boroughs.size()];
174 |
175 | for (int i = 0; i < boroughs.size(); i++) {
176 | MultiPolygon borough = boroughs.get(i);
177 | double value = values.get(borough);
178 |
179 | Map properties = new HashMap<>();
180 | properties.put("name", names.get(borough));
181 | properties.put("restaurants", counters.get(borough));
182 | properties.put("fill", color(value));
183 | properties.put("fill-opacity", "0.5");
184 | properties.put("stroke", "#555555");
185 |
186 | GeoJSONWriter writer = new GeoJSONWriter();
187 | org.wololo.geojson.Geometry g = writer.write(borough);
188 | features[i] = new Feature(g, properties);
189 | }
190 |
191 | FeatureCollection featureCollection = new FeatureCollection(features);
192 |
193 | String json = featureCollection.toString();
194 |
195 | System.out.println(GeoJsonHelper.prettyPrintFeatureCollection(json));
196 | }
197 |
198 | // Interpolate a color between color0 and color1. Parameter value is in
199 | // [0..1]. value = 0 maps to color0 and value = 1 maps to color1.
200 | // Interpolate linearly in between.
201 | private static String color(double value)
202 | {
203 | int color0 = 0xffa200;
204 | int color1 = 0x3829ff;
205 |
206 | int r0 = (color0 >> 16) & 0xFF;
207 | int g0 = (color0 >> 8) & 0xFF;
208 | int b0 = (color0) & 0xFF;
209 |
210 | int r1 = (color1 >> 16) & 0xFF;
211 | int g1 = (color1 >> 8) & 0xFF;
212 | int b1 = (color1) & 0xFF;
213 |
214 | int r = (int) Math.round((1 - value) * r0 + value * r1);
215 | int g = (int) Math.round((1 - value) * g0 + value * g1);
216 | int b = (int) Math.round((1 - value) * b0 + value * b1);
217 |
218 | return String.format("#%02x%02x%02x", r, g, b);
219 | }
220 |
221 | }
222 |
--------------------------------------------------------------------------------
/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=WARN, A1
2 |
3 | log4j.logger.de.topobyte.osm4j.examples=INFO
4 |
5 | log4j.appender.A1=org.apache.log4j.ConsoleAppender
6 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout
7 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
8 |
--------------------------------------------------------------------------------