mirror of https://gitee.com/openkylin/libkml.git
Import Upstream version 1.3.0
This commit is contained in:
commit
f7ffe4988c
|
@ -0,0 +1,12 @@
|
|||
language: cpp
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
before_script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install swig python-dev
|
||||
|
||||
script: cmake -DCMAKE_INSTALL_PREFIX=../../install .. && make
|
|
@ -0,0 +1,218 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
project(LibKML)
|
||||
|
||||
set(VERSION_MAJOR "1")
|
||||
set(VERSION_MINOR "3")
|
||||
set(VERSION_PATCH "0")
|
||||
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
|
||||
option(BUILD_TESTING "Build testing." OFF)
|
||||
option(BUILD_EXAMPLES "Build examples." OFF)
|
||||
option(INSTALL_EXAMPLES "Install examples sources and executables" OFF)
|
||||
option(BUILD_SHARED_LIBS "Build shared libs." ON)
|
||||
|
||||
option(WITH_SWIG "Build all swig bindings" OFF)
|
||||
option(WITH_PYTHON "Build python bindings" OFF)
|
||||
option(WITH_JAVA "Build java bindings" OFF)
|
||||
|
||||
set(LIBKML_DATA_DIR ${CMAKE_SOURCE_DIR}/testdata CACHE "Directory containing test data" PATH)
|
||||
|
||||
#AM_CXXFLAGS = -Wall -Wextra -Wno-unused-parameter -pedantic -fno-rtti
|
||||
#AM_TEST_CXXFLAGS = -Wall -Wextra -Wno-unused-parameter -Werror -fno-rtti -DGTEST_HAS_RTTI=0
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -pedantic -fno-rtti")
|
||||
set(TEST_FLAGS "-Wall -Wextra -Wno-unused-parameter -fno-rtti -DGTEST_HAS_RTTI=0")
|
||||
|
||||
else()
|
||||
if(MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DUNICODE /D_UNICODE")
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
if(NOT DEFINED BIN_INSTALL_DIR)
|
||||
set(BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin")
|
||||
endif(NOT DEFINED BIN_INSTALL_DIR)
|
||||
if(NOT DEFINED LIB_INSTALL_DIR)
|
||||
set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib")
|
||||
endif(NOT DEFINED LIB_INSTALL_DIR)
|
||||
if(NOT DEFINED DATA_INSTALL_DIR)
|
||||
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share")
|
||||
endif(NOT DEFINED DATA_INSTALL_DIR)
|
||||
if(NOT DEFINED INCLUDE_INSTALL_DIR)
|
||||
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/kml")
|
||||
endif(NOT DEFINED INCLUDE_INSTALL_DIR)
|
||||
if(NOT DEFINED MAN_INSTALL_DIR)
|
||||
set(MAN_INSTALL_DIR "${DATA_INSTALL_DIR}/man")
|
||||
endif(NOT DEFINED MAN_INSTALL_DIR)
|
||||
if(NOT DEFINED RESOURCE_INSTALL_DIR)
|
||||
set(RESOURCE_INSTALL_DIR "${DATA_INSTALL_DIR}/libkml${VERSION_MAJOR}/resource/")
|
||||
endif(NOT DEFINED RESOURCE_INSTALL_DIR)
|
||||
if(NOT DEFINED LOCALE_INSTALL_DIR)
|
||||
set(LOCALE_INSTALL_DIR "${DATA_INSTALL_DIR}/locale/")
|
||||
endif(NOT DEFINED LOCALE_INSTALL_DIR)
|
||||
if(NOT DEFINED JAVA_INSTALL_DIR)
|
||||
set(JAVA_INSTALL_DIR "${DATA_INSTALL_DIR}/java")
|
||||
endif(NOT DEFINED JAVA_INSTALL_DIR)
|
||||
if(NOT DEFINED JNI_INSTALL_DIR)
|
||||
set(JNI_INSTALL_DIR "${LIB_INSTALL_DIR}/jni")
|
||||
endif(NOT DEFINED JNI_INSTALL_DIR)
|
||||
if(NOT DEFINED PKGCONFIG_INSTALL_DIR)
|
||||
set(PKGCONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/pkgconfig")
|
||||
endif(NOT DEFINED PKGCONFIG_INSTALL_DIR)
|
||||
|
||||
if(WIN32 AND NOT CYGWIN)
|
||||
set(DEF_INSTALL_CMAKE_DIR cmake)
|
||||
else()
|
||||
set(DEF_INSTALL_CMAKE_DIR lib/cmake/libkml)
|
||||
endif()
|
||||
set(CMAKE_INSTALL_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
|
||||
|
||||
set(INSTALL_DIR "${CMAKE_INSTALL_PREFIX}" CACHE "install directory " PATH)
|
||||
|
||||
# Path to additional CMake modules
|
||||
set(CMAKE_MODULE_PATH
|
||||
${CMAKE_SOURCE_DIR}/cmake
|
||||
${CMAKE_MODULE_PATH})
|
||||
|
||||
include(LibKMLHelper)
|
||||
|
||||
include(ExternalProject)
|
||||
|
||||
set(KMLBASE_LINK_LIBS "" CACHE INTERNAL "KMLBASE_LINK_LIBS")
|
||||
set(KMLBASE_DEPENDS "" CACHE INTERNAL "KMLBASE_DEPENDS")
|
||||
set(MINIZIP_DEPENDS "" CACHE INTERNAL "MINIZIP_DEPENDS")
|
||||
|
||||
set(LIBKML_TARGETS)
|
||||
|
||||
find_package(EXPAT)
|
||||
if(EXPAT_FOUND)
|
||||
include_directories(${EXPAT_INCLUDE_DIR})
|
||||
else()
|
||||
include(External_expat)
|
||||
list(APPEND KMLBASE_DEPENDS EXPAT)
|
||||
endif()
|
||||
|
||||
find_package(ZLIB 1.2.8)
|
||||
if(ZLIB_FOUND)
|
||||
include_directories(${ZLIB_INCLUDE_DIR})
|
||||
else()
|
||||
include(External_zlib)
|
||||
list(APPEND KMLBASE_DEPENDS ZLIB)
|
||||
list(APPEND MINIZIP_DEPENDS ZLIB)
|
||||
endif()
|
||||
|
||||
find_package(MiniZip)
|
||||
if(MINIZIP_FOUND)
|
||||
include_directories(${MINIZIP_INCLUDE_DIR})
|
||||
else()
|
||||
include(External_minizip)
|
||||
list(APPEND KMLBASE_DEPENDS MINIZIP)
|
||||
endif()
|
||||
|
||||
find_package(UriParser)
|
||||
if(URIPARSER_FOUND)
|
||||
include_directories(${URIPARSER_INCLUDE_DIR})
|
||||
else()
|
||||
include(External_uriparser)
|
||||
list(APPEND KMLBASE_DEPENDS URIPARSER)
|
||||
endif()
|
||||
|
||||
find_package(Boost)
|
||||
if(Boost_FOUND)
|
||||
message(STATUS "Found Boost: ${Boost_VERSION}")
|
||||
else()
|
||||
include(External_boost)
|
||||
list(APPEND KMLBASE_DEPENDS BOOST)
|
||||
message(STATUS "Found Boost includes: ${Boost_INCLUDE_DIRS}")
|
||||
endif()
|
||||
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
if(WITH_SWIG)
|
||||
find_package(SWIG)
|
||||
if(SWIG_EXECUTABLE)
|
||||
include(${SWIG_USE_FILE})
|
||||
else()
|
||||
set(WITH_SWIG OFF)
|
||||
set(WITH_PYTHON OFF)
|
||||
set(WITH_JAVA OFF)
|
||||
message(WARNING "Swig not found. Hence bindings will not be built")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list(APPEND KMLBASE_LINK_LIBS ${EXPAT_LIBRARY})
|
||||
list(APPEND KMLBASE_LINK_LIBS ${ZLIB_LIBRARY})
|
||||
list(APPEND KMLBASE_LINK_LIBS ${MINIZIP_LIBRARY})
|
||||
list(APPEND KMLBASE_LINK_LIBS ${URIPARSER_LIBRARY})
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
configure_file("${CMAKE_SOURCE_DIR}/cmake/libkml.pc.in"
|
||||
"${CMAKE_BINARY_DIR}/libkml.pc" @ONLY)
|
||||
|
||||
install(FILES ${CMAKE_BINARY_DIR}/libkml.pc
|
||||
DESTINATION ${PKGCONFIG_INSTALL_DIR})
|
||||
|
||||
if(BUILD_TESTING)
|
||||
enable_testing()
|
||||
find_package(GoogleTest REQUIRED)
|
||||
include_directories(${GTEST_INCLUDE_DIR})
|
||||
include_directories(${CMAKE_SOURCE_DIR}/tests)
|
||||
add_definitions("-DDATADIR=\"${LIBKML_DATA_DIR}\"")
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
if(BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
string(TOUPPER ${CMAKE_BUILD_TYPE} CONFIG_TYPE)
|
||||
|
||||
# Make relative paths absolute (needed later on)
|
||||
foreach(p LIB BIN INCLUDE CMAKE)
|
||||
set(var ${p}_INSTALL_DIR)
|
||||
if(NOT IS_ABSOLUTE "${${var}}")
|
||||
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
export(TARGETS ${LIBKML_TARGETS}
|
||||
FILE "${CMAKE_BINARY_DIR}/LibKMLTargets.cmake")
|
||||
|
||||
# Create the LibKMLConfig.cmake and LibKMLConfigVersion files
|
||||
file(RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_DIR}"
|
||||
"${INCLUDE_INSTALL_DIR}")
|
||||
|
||||
# ... for the build tree
|
||||
set(CONF_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/src")
|
||||
configure_file(cmake/LibKMLConfig.cmake.in
|
||||
"${PROJECT_BINARY_DIR}/LibKMLConfig.cmake" @ONLY)
|
||||
|
||||
# ... for the install tree
|
||||
set(CONF_INCLUDE_DIRS "\${LIBKML_CMAKE_DIR}/${REL_INCLUDE_DIR}")
|
||||
configure_file(cmake/LibKMLConfig.cmake.in
|
||||
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibKMLConfig.cmake" @ONLY)
|
||||
|
||||
# ... for both
|
||||
configure_file(cmake/LibKMLConfigVersion.cmake.in
|
||||
"${CMAKE_BINARY_DIR}/LibKMLConfigVersion.cmake" @ONLY)
|
||||
|
||||
# Install the LibKMLConfig.cmake and LibKMLConfigVersion.cmake
|
||||
install(FILES
|
||||
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibKMLConfig.cmake"
|
||||
"${CMAKE_BINARY_DIR}/LibKMLConfigVersion.cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_DIR}" )
|
||||
|
||||
# Install the export set for use with the install-tree
|
||||
install(EXPORT LibKMLTargets DESTINATION "${CMAKE_INSTALL_DIR}")
|
|
@ -0,0 +1,25 @@
|
|||
Copyright 2008, Google Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
The project wiki contains a UserGuideXXX page that acts as both a quick guide
|
||||
to the most recent release and what's changed since the previous release. See:
|
||||
http://code.google.com/p/libkml/w/list
|
|
@ -0,0 +1,25 @@
|
|||
This file records the source URL and latest version of each external package
|
||||
used by libkml. Other versions may work fine. The given version are based on the official linux packages on Fedora 21.
|
||||
|
||||
If you have trouble building, create an issue on github.com/libkml/libkml
|
||||
|
||||
|
||||
Required:
|
||||
g++: version higher than 4.4 is tested
|
||||
expat: expat.sourceforge.net version >= 2.1.0
|
||||
zlib: www.zlib.net version >= 1.2.8
|
||||
boost: www.boost.org version >= 1.44.0
|
||||
minizip: >= 1.2.8
|
||||
googletest: http://googletest.googlecode.com >= 1.7.0
|
||||
|
||||
Optional:
|
||||
java: java.sun.com 1.5.0_13, 1.6.0_04
|
||||
python: www.python.org 2.7
|
||||
swig: www.swig.org 2.0
|
||||
|
||||
Development:
|
||||
cmake: www.cmake.org >= 2.8
|
||||
|
||||
|
||||
|
||||
NOTE: This file will be changed to markdown or RST soon..
|
|
@ -0,0 +1,78 @@
|
|||
Installation Instructions
|
||||
*************************
|
||||
|
||||
Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved. This file is offered as-is,
|
||||
without warranty of any kind.
|
||||
|
||||
Basic Installation
|
||||
==================
|
||||
|
||||
Briefly, the shell commands `mkdir build; cmake ..; make; make install' should
|
||||
configure, build, and install this package. The following
|
||||
more-detailed instructions are generic; see the `README' file for
|
||||
instructions specific to this package. Some packages provide this
|
||||
`INSTALL' file but do not implement all of the features documented
|
||||
below. The lack of an optional feature in a given package is not
|
||||
necessarily a bug. More recommendations for GNU packages can be found
|
||||
in *note Makefile Conventions: (standards)Makefile Conventions.
|
||||
|
||||
The `configure' shell script attempts to guess correct values for
|
||||
various system-dependent variables used during compilation. It uses
|
||||
those values to create a `Makefile' in each directory of the package.
|
||||
It may also create one or more `.h' files containing system-dependent
|
||||
definitions. Finally, it creates a shell script `config.status' that
|
||||
you can run in the future to recreate the current configuration, and a
|
||||
file `config.log' containing compiler output (useful mainly for
|
||||
debugging `configure').
|
||||
|
||||
It can also use an optional file (typically called `config.cache'
|
||||
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
||||
the results of its tests to speed up reconfiguring. Caching is
|
||||
disabled by default to prevent problems with accidental use of stale
|
||||
cache files.
|
||||
|
||||
If you need to do unusual things to compile the package, please try
|
||||
to figure out how `configure' could check whether to do them, and mail
|
||||
diffs or instructions to the address given in the `README' so they can
|
||||
be considered for the next release. If you are using the cache, and at
|
||||
some point `config.cache' contains results you don't want to keep, you
|
||||
may remove or edit it.
|
||||
|
||||
The file `configure.ac' (or `configure.in') is used to create
|
||||
`configure' by a program called `autoconf'. You need `configure.ac' if
|
||||
you want to change it or regenerate `configure' using a newer version
|
||||
of `autoconf'.
|
||||
|
||||
The simplest way to compile this package is:
|
||||
|
||||
1. `cd /path/to/libkml/sources and create a directory
|
||||
to keep build files. eg: '/path/to/libkml/sources/build'
|
||||
`mkdir build; cd build`
|
||||
|
||||
2. Run cmake from build directory
|
||||
`cmake /path/to/libkml/sources' to configure the package for your system.
|
||||
|
||||
3. Optionally, set cmake variable BUILD_TESTING=ON to build testing code.
|
||||
Later after compiling you can run test suite via launching ctest
|
||||
|
||||
4. Type `make' to compile the package.
|
||||
|
||||
5. Type `make install' to install the programs and any data files and
|
||||
documentation. When installing into a prefix owned by root, it is
|
||||
recommended that the package be configured and built as a regular
|
||||
user, and only the `make install' phase executed with root
|
||||
privileges.
|
||||
|
||||
|
||||
Installation Names
|
||||
==================
|
||||
|
||||
By default, `make install' installs the package's commands under
|
||||
`/usr/local/bin', include files under `/usr/local/include', etc. You
|
||||
can specify an installation prefix other than `/usr/local' by changing
|
||||
cmake variable CMAKE_INSTALL_PREFIX=
|
|
@ -0,0 +1,25 @@
|
|||
Copyright 2010, Google Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
![Awesome logo](bactrian128.png)
|
||||
|
||||
[![Travis Build Status](https://travis-ci.org/libkml/libkml.png?branch=master)](https://travis-ci.org/libkml/libkml)
|
||||
[![Coverity Scan Build Status](https://scan.coverity.com/projects/4788/badge.svg)](https://scan.coverity.com/projects/4788)
|
||||
|
||||
This is Google's reference implementation of [OGC KML 2.2](http://www.opengeospatial.org/standards/kml). It also includes implementations of Google's `gx:` extensions used by Google Earth, as well as several utility libraries for working with other formats.
|
||||
|
||||
All of original documentation written by google is imported into "wiki" branch:
|
||||
https://github.com/libkml/libkml/tree/wiki
|
||||
|
||||
The wiki contains documents that describe:
|
||||
- An overview of the most recent release
|
||||
- Building and running the code
|
||||
- Running the unit tests
|
||||
- A general API reference guide
|
||||
- More details guides to each of the libkml modules
|
||||
|
||||
This libkml project was imported from code.google.com using their "Export to Github" tool and then all commits from google/libkml and rashadkm/libkml were merged.
|
||||
|
||||
All issues and wiki from code.google.com have also been imported, thanks to GoogleCodeExporter tool.
|
||||
|
||||
The primary motivation for the fork is the lack of alternatives to the libkml library. Most of the open source GIS projects uses this library for processing kml/kmz filesnotably GDAL, OSSIM, OTB and osgEarth. The development of the libkml project has been shelved by Google without any publicly stated reason so far.
|
||||
|
||||
Contacting the libkml maintainers on code.google.com failed to get a response. Google copied the project from code.google.com to GitHub and the GitHub repository was a little more active in terms of commits for a short while. Via the GitHub issue https://github.com/google/libkml/issues/4 another attempt to get feedback from Google was made, but other than the discussion between Bas Couwenberg and Rashad and a comment by Simon there was no response from anybody else. Because of that the decision was made to attempt to revitalize the libkml project with a fork on GitHub. At this point, the github way or forking from google/libkml and sending back a Pull Requests would also result in no effect.
|
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
|
@ -0,0 +1,10 @@
|
|||
ExternalProject_Add(BOOST
|
||||
PREFIX BOOST
|
||||
URL "http://sourceforge.net/projects/boost/files/boost-binaries/1.50.0/boost_1_50_headers.zip/download"
|
||||
URL_MD5 1605dc6085cb2dc778ef5ab6c0e59083
|
||||
SOURCE_DIR ${INSTALL_DIR}/include/boost
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND "" )
|
||||
|
||||
set(Boost_INCLUDE_DIRS ${INSTALL_DIR}/include)
|
|
@ -0,0 +1,15 @@
|
|||
ExternalProject_Add(EXPAT
|
||||
PREFIX EXPAT
|
||||
URL "http://sourceforge.net/projects/expat/files/expat/2.1.0/expat-2.1.0.tar.gz/download"
|
||||
URL_MD5 dd7dab7a5fea97d2a6a43f511449b7cd
|
||||
BINARY_DIR ${CMAKE_BINARY_DIR}/EXPAT/build
|
||||
DOWNLOAD_DIR ${DOWNLOAD_LOCATION}
|
||||
CMAKE_CACHE_ARGS
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR}
|
||||
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
|
||||
-DBUILD_examples:BOOL=OFF
|
||||
-DBUILD_tests:BOOL=OFF
|
||||
-DBUILD_tools:BOOL=OFF
|
||||
-DBUILD_shared:BOOL=${BUILD_SHARED_LIBS})
|
||||
|
||||
include_project_vars(EXPAT "libexpat")
|
|
@ -0,0 +1,18 @@
|
|||
ExternalProject_Add(MINIZIP
|
||||
PREFIX MINIZIP
|
||||
URL "http://sourceforge.net/projects/libkml-files/files/1.3.0/minizip.tar.gz/download"
|
||||
URL_MD5 d5f74eff74e03e497ea60b2c43623416
|
||||
BINARY_DIR ${CMAKE_BINARY_DIR}/MINIZIP/build
|
||||
DEPENDS ${MINIZIP_DEPENDS}
|
||||
CMAKE_CACHE_ARGS
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR}
|
||||
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
|
||||
-DZLIB_INCLUDE_DIR:PATH=${ZLIB_INCLUDE_DIR}
|
||||
-DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARY}
|
||||
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS} )
|
||||
|
||||
if(MSVC)
|
||||
include_project_vars(MINIZIP "minizip")
|
||||
else()
|
||||
include_project_vars(MINIZIP "libminizip")
|
||||
endif()
|
|
@ -0,0 +1,18 @@
|
|||
ExternalProject_Add(URIPARSER
|
||||
PREFIX URIPARSER
|
||||
URL "http://sourceforge.net/projects/uriparser/files/Sources/0.7.5/uriparser-0.7.5.tar.bz2/download"
|
||||
URL_MD5 4f4349085fe5de33bcae8d0f26649593
|
||||
BINARY_DIR ${CMAKE_BINARY_DIR}/URIPARSER/build
|
||||
DOWNLOAD_DIR ${DOWNLOAD_LOCATION}
|
||||
PATCH_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/cmake/UriParser_cmake_lists_txt ${CMAKE_BINARY_DIR}/URIPARSER/src/URIPARSER/CMakeLists.txt
|
||||
CMAKE_CACHE_ARGS
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR}
|
||||
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
|
||||
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS} )
|
||||
|
||||
|
||||
if(MSVC)
|
||||
include_project_vars(URIPARSER "uriparser")
|
||||
else()
|
||||
include_project_vars(URIPARSER "liburiparser")
|
||||
endif()
|
|
@ -0,0 +1,20 @@
|
|||
ExternalProject_Add(ZLIB
|
||||
PREFIX ZLIB
|
||||
URL "http://zlib.net/zlib-1.2.8.tar.gz"
|
||||
URL_MD5 44d667c142d7cda120332623eab69f40
|
||||
BINARY_DIR ${CMAKE_BINARY_DIR}/ZLIB/build
|
||||
DOWNLOAD_DIR ${DOWNLOAD_LOCATION}
|
||||
CMAKE_CACHE_ARGS
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR}
|
||||
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
|
||||
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS})
|
||||
|
||||
if(MSVC)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
include_project_vars(ZLIB "zlib")
|
||||
else()
|
||||
include_project_vars(ZLIB "zlibstatic")
|
||||
endif()
|
||||
else()
|
||||
include_project_vars(ZLIB "libz")
|
||||
endif()
|
|
@ -0,0 +1,40 @@
|
|||
# Find the Google Test Framework
|
||||
# Defines:
|
||||
|
||||
# GTEST_INCLUDE_DIR - gtest include directory
|
||||
# GTEST_LIBRARY - gtest library file
|
||||
# GTEST_FOUND - TRUE if gtest is found
|
||||
|
||||
if (GTEST_INCLUDE_DIR)
|
||||
#check cache
|
||||
set(GTEST_FIND_QUIETLY TRUE)
|
||||
endif ()
|
||||
|
||||
|
||||
if (NOT GTEST_INCLUDE_DIR)
|
||||
find_path(GTEST_INCLUDE_DIR NAMES gtest.h PATH_SUFFIXES gtest)
|
||||
set(GTEST_INCLUDE_DIR ${GTEST_INCLUDE_DIR}/gtest CACHE PATH "Google Test includes")
|
||||
endif ()
|
||||
|
||||
find_library(GTESTMAIN_LIB NAMES gtest_main)
|
||||
|
||||
find_library(GTEST_LIB NAMES gtest)
|
||||
|
||||
if (GTEST_INCLUDE_DIR AND GTEST_LIB AND GTESTMAIN_LIB)
|
||||
set(GTEST_FOUND TRUE)
|
||||
set(GTEST_LIBRARY ${GTEST_LIB} ${GTESTMAIN_LIB})
|
||||
endif ()
|
||||
|
||||
if (GTEST_FOUND)
|
||||
if (NOT GTEST_FIND_QUIETLY)
|
||||
message(STATUS "Found Google Test Framework: ${GTEST_LIBRARY}")
|
||||
endif ()
|
||||
else ()
|
||||
if (GTEST_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could NOT find Google Test Framework")
|
||||
else ()
|
||||
message(STATUS "Could NOT find Google Test Framework")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
# Find the MiniZip library
|
||||
# Defines:
|
||||
|
||||
# MINIZIP_INCLUDE_DIR - MiniZip includes
|
||||
# MINIZIP_LIBRARY - MiniZip libraries
|
||||
# MINIZIP_FOUND - TRUE if minizip is found
|
||||
|
||||
|
||||
if(MINIZIP_INCLUDE_DIR)
|
||||
#check cache
|
||||
set(MINIZIP_FIND_QUIETLY TRUE)
|
||||
endif()
|
||||
|
||||
if(NOT MINIZIP_INCLUDE_DIR)
|
||||
find_path(MINIZIP_INCLUDE_DIR NAMES minizip/unzip.h minizip/zip.h)
|
||||
endif()
|
||||
|
||||
find_library(MINIZIP_LIBRARY NAMES minizip)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(MINIZIP DEFAULT_MSG MINIZIP_LIBRARY MINIZIP_INCLUDE_DIR )
|
||||
|
||||
mark_as_advanced(MINIZIP_INCLUDE_DIR MINIZIP_LIBRARY)
|
||||
|
||||
if(MINIZIP_FOUND)
|
||||
set(MINIZIP_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIR})
|
||||
set(MINIZIP_LIBRARIES ${MINIZIP_LIBRARY})
|
||||
else()
|
||||
set(MINIZIP_INCLUDE_DIRS)
|
||||
set(MINIZIP_LIBRARIES)
|
||||
endif()
|
|
@ -0,0 +1,31 @@
|
|||
# Find the UriParser library
|
||||
# Defines:
|
||||
|
||||
# URIPARSER_INCLUDE_DIR - UriParser include directory
|
||||
# URIPARSER_LIBRARY - UriParser library file
|
||||
# URIPARSER_FOUND - TRUE if UriParser is found
|
||||
|
||||
if (URIPARSER_INCLUDE_DIR)
|
||||
#check cache
|
||||
set(URIPARSER_FIND_QUIETLY TRUE)
|
||||
endif ()
|
||||
|
||||
|
||||
if (NOT URIPARSER_INCLUDE_DIR)
|
||||
find_path(URIPARSER_INCLUDE_DIR NAMES uriparser/Uri.h uriparser/UriBase.h )
|
||||
endif ()
|
||||
|
||||
find_library(URIPARSER_LIBRARY NAMES uriparser)
|
||||
|
||||
include( FindPackageHandleStandardArgs )
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS( URIPARSER DEFAULT_MSG URIPARSER_LIBRARY URIPARSER_INCLUDE_DIR )
|
||||
|
||||
mark_as_advanced( URIPARSER_INCLUDE_DIR URIPARSER_LIBRARY )
|
||||
|
||||
if(URIPARSER_FOUND)
|
||||
set(URIPARSER_INCLUDE_DIRS ${URIPARSER_INCLUDE_DIR})
|
||||
set(URIPARSER_LIBRARIES ${URIPARSER_LIBRARY})
|
||||
else()
|
||||
set(URIPARSER_INCLUDE_DIRS)
|
||||
set(URIPARSER_LIBRARIES)
|
||||
endif()
|
|
@ -0,0 +1,22 @@
|
|||
# Compute paths
|
||||
get_filename_component(LIBKML_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
|
||||
set(LIBKML_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@")
|
||||
|
||||
if(NOT TARGET foo AND NOT LIBKML_BINARY_DIR)
|
||||
include("${LIBKML_CMAKE_DIR}/LibKMLTargets.cmake")
|
||||
endif()
|
||||
|
||||
set(LIBKML_LIBRARIES)
|
||||
|
||||
foreach(targ @LIBKML_TARGETS@)
|
||||
get_target_property(LIB_LIB_FILENAME ${targ} IMPORTED_LOCATION_@CONFIG_TYPE@)
|
||||
get_target_property(LIB_LINK_FILENAME ${targ} IMPORTED_LINK_INTERFACE_LIBRARIES_@CONFIG_TYPE@)
|
||||
string(REGEX MATCH "^kml" matched ${LIB_LINK_FILENAME})
|
||||
if(NOT matched)
|
||||
list(APPEND LIBKML_LIBRARIES ${LIB_LINK_FILENAME})
|
||||
endif()
|
||||
list(APPEND LIBKML_LIBRARIES ${LIB_LIB_FILENAME})
|
||||
endforeach()
|
||||
|
||||
set(LIBKML_FOUND TRUE)
|
|
@ -0,0 +1,11 @@
|
|||
set(PACKAGE_VERSION "@VERSION_STRING@")
|
||||
|
||||
# Check whether the requested PACKAGE_FIND_VERSION is compatible
|
||||
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
|
||||
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||
else()
|
||||
set(PACKAGE_VERSION_COMPATIBLE TRUE)
|
||||
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
|
||||
set(PACKAGE_VERSION_EXACT TRUE)
|
||||
endif()
|
||||
endif()
|
|
@ -0,0 +1,74 @@
|
|||
macro(build_target)
|
||||
cmake_parse_arguments(LIB "" "NAME" "SRCS;INCS;LINKS;DEPENDS" ${ARGN} )
|
||||
add_library(${LIB_NAME} ${LIB_SRCS})
|
||||
|
||||
foreach(LIB_DEPEND ${LIB_DEPENDS})
|
||||
add_dependencies(${LIB_NAME} ${LIB_DEPEND})
|
||||
#well.. if the LIB_DEPEND is one of kml*
|
||||
#then we need to link it with target lib
|
||||
if(${LIB_DEPEND} MATCHES "^kml")
|
||||
list(APPEND LIB_LINKS ${LIB_DEPEND})
|
||||
endif()
|
||||
endforeach()
|
||||
target_link_libraries(${LIB_NAME} ${LIB_LINKS})
|
||||
if(VERSION_STRING)
|
||||
set_target_properties(${LIB_NAME} PROPERTIES
|
||||
VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
|
||||
SOVERSION "${VERSION_MAJOR}")
|
||||
endif()
|
||||
string(LENGTH ${LIB_NAME} ${LIB_NAME}_LEN)
|
||||
MATH(EXPR ${LIB_NAME}_END "${${LIB_NAME}_LEN} - 3")
|
||||
string(SUBSTRING ${LIB_NAME} 3 ${${LIB_NAME}_END} ${LIB_NAME}_INCLUDE_DIR)
|
||||
install(
|
||||
FILES ${LIB_INCS}
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}/${${LIB_NAME}_INCLUDE_DIR})
|
||||
|
||||
install_target(${LIB_NAME})
|
||||
|
||||
endmacro(build_target)
|
||||
|
||||
macro(install_target _target)
|
||||
install(TARGETS ${_target}
|
||||
EXPORT LibKMLTargets
|
||||
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
|
||||
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
|
||||
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
|
||||
|
||||
list(LENGTH LIBKML_TARGETS LIBKML_TARGETS_LENGTH)
|
||||
if(LIBKML_TARGETS_LENGTH LESS 1)
|
||||
set(LIBKML_TARGETS "${_target}" PARENT_SCOPE)
|
||||
else()
|
||||
set(LIBKML_TARGETS "${LIBKML_TARGETS};${_target}" PARENT_SCOPE)
|
||||
endif()
|
||||
endmacro(install_target)
|
||||
|
||||
function(build_test)
|
||||
cmake_parse_arguments(TEST "" "GROUP;NAME" "LINKS;DEPENDS" ${ARGN} )
|
||||
add_executable(test_${TEST_NAME} ${TEST_NAME}_test.cc)
|
||||
add_dependencies(test_${TEST_NAME} ${TEST_DEPENDS})
|
||||
target_link_libraries(test_${TEST_NAME} ${TEST_DEPENDS} ${TEST_LINKS} ${GTEST_LIBRARY})
|
||||
add_test(${TEST_GROUP}_${TEST_NAME} ${CMAKE_BINARY_DIR}/bin/test_${TEST_NAME})
|
||||
endfunction(build_test)
|
||||
|
||||
function(build_example)
|
||||
cmake_parse_arguments(EXAMPLE "" "NAME" "LINKS;DEPENDS" ${ARGN} )
|
||||
add_executable(example_${EXAMPLE_NAME} ${EXAMPLE_NAME}.cc)
|
||||
add_dependencies(example_${EXAMPLE_NAME} ${EXAMPLE_DEPENDS})
|
||||
target_link_libraries(example_${EXAMPLE_NAME} ${EXAMPLE_LINKS} ${EXAMPLE_DEPENDS})
|
||||
endfunction(build_example)
|
||||
|
||||
|
||||
macro(include_project_vars _project _lib)
|
||||
set(${_project}_INCLUDE_DIR "${INSTALL_DIR}/include")
|
||||
if(WIN32)
|
||||
set(_suffix ${CMAKE_LINK_LIBRARY_SUFFIX})
|
||||
else(UNIX)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
else()
|
||||
set(_suffix ".a")
|
||||
endif()
|
||||
endif(WIN32)
|
||||
set(${_project}_LIBRARY "${INSTALL_DIR}/lib/${_lib}${_suffix}")
|
||||
include_directories(${${_project}_INCLUDE_DIR})
|
||||
endmacro()
|
|
@ -0,0 +1,39 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(SRCS
|
||||
lib/UriCommon.c
|
||||
lib/UriCommon.h
|
||||
lib/UriCompare.c
|
||||
lib/UriEscape.c
|
||||
lib/UriFile.c
|
||||
lib/UriIp4.c
|
||||
lib/UriIp4Base.c
|
||||
lib/UriIp4Base.h
|
||||
lib/UriNormalize.c
|
||||
lib/UriNormalizeBase.c
|
||||
lib/UriNormalizeBase.h
|
||||
lib/UriParse.c
|
||||
lib/UriParseBase.c
|
||||
lib/UriParseBase.h
|
||||
lib/UriQuery.c
|
||||
lib/UriRecompose.c
|
||||
lib/UriResolve.c
|
||||
lib/UriShorten.c)
|
||||
|
||||
set(INCS
|
||||
include/uriparser/Uri.h
|
||||
include/uriparser/UriBase.h
|
||||
include/uriparser/UriDefsAnsi.h
|
||||
include/uriparser/UriDefsConfig.h
|
||||
include/uriparser/UriDefsUnicode.h
|
||||
include/uriparser/UriIp4.h)
|
||||
|
||||
include_directories(include)
|
||||
add_library(uriparser ${SRCS})
|
||||
|
||||
install(TARGETS uriparser
|
||||
DESTINATION lib)
|
||||
|
||||
install(FILES ${INCS}
|
||||
DESTINATION include/uriparser/)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# pkg-config source file
|
||||
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${exec_prefix}/lib
|
||||
includedir=${prefix}/include
|
||||
|
||||
Name: LibKML
|
||||
Description: Reference implementation of OGC KML 2.2
|
||||
Version: @VERSION_STRING@
|
||||
##Requires: expat zlib boost
|
||||
##minizip
|
||||
Conflicts:
|
||||
Libs: -L${libdir} -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator
|
||||
Cflags: -I${includedir}
|
|
@ -0,0 +1,3 @@
|
|||
import compileall
|
||||
from sys import argv
|
||||
compileall.compile_file(argv[1])
|
|
@ -0,0 +1,3 @@
|
|||
Documentation for libkml can be found at the project's wiki:
|
||||
http://code.google.com/p/libkml/w/list
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
add_subdirectory(domviewer)
|
||||
add_subdirectory(engine)
|
||||
add_subdirectory(gpx)
|
||||
add_subdirectory(gx)
|
||||
|
||||
find_package(CURL)
|
||||
if(NOT CURL_FOUND)
|
||||
message(WARNING "Examples in hellonet directory are not built because curl was not found")
|
||||
else()
|
||||
add_subdirectory(hellonet)
|
||||
endif()
|
||||
|
||||
add_subdirectory(helloworld)
|
||||
|
||||
add_subdirectory(java)
|
||||
add_subdirectory(kml)
|
||||
# add_subdirectory(perl)
|
||||
# add_subdirectory(php)
|
||||
add_subdirectory(python)
|
||||
#add_subdirectory(ruby)
|
||||
add_subdirectory(regionator)
|
||||
# add_subdirectory(wxregionator)
|
||||
# add_subdirectory(wxviewer)
|
||||
add_subdirectory(xsd)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
if(INSTALL_EXAMPLES)
|
||||
install( FILES kml-aliases.txt DESTINATION ${KML_EXAMPLES_DIR} COMPONENT Development)
|
||||
endif()
|
|
@ -0,0 +1,204 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# Copyright 2008, Google Inc. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# A simple graphical application that parses a local or remote KML or KMZ file
|
||||
# and displays the parsed Features in a tree format.
|
||||
# Usage: call ./domviewer.py from a terminal command line, then use the
|
||||
# File > Open File command to load a file. You may also supply a file
|
||||
# (local filesystem or over http) to open on the command line as
|
||||
# ./domviewer.py input.kml
|
||||
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import urllib2
|
||||
import zipfile
|
||||
from idlelib.TreeWidget import TreeItem, TreeNode
|
||||
from Tkinter import *
|
||||
from tkFileDialog import askopenfilename
|
||||
from tkSimpleDialog import askstring
|
||||
from tkMessageBox import showwarning
|
||||
import kmldom
|
||||
|
||||
class DomTreeItem(TreeItem):
|
||||
def __init__(self, element):
|
||||
self.__element = element
|
||||
if element.has_name():
|
||||
self.__name = element.get_name()
|
||||
elif element.IsA(kmldom.Type_Document):
|
||||
self.__name = 'Unnamed Document'
|
||||
elif element.IsA(kmldom.Type_Folder):
|
||||
self.__name = 'Unnamed Folder'
|
||||
elif element.IsA(kmldom.Type_Placemark):
|
||||
self.__name = 'Unnamed Placemark'
|
||||
elif element.IsA(kmldom.Type_ScreenOverlay):
|
||||
self.__name = 'Unnamed ScreenOverlay'
|
||||
elif element.IsA(kmldom.Type_PhotoOverlay):
|
||||
self.__name = 'Unnamed PhotoOverlay'
|
||||
elif element.IsA(kmldom.Type_GroundOverlay):
|
||||
self.__name = 'Unnamed GroundOverlay'
|
||||
elif element.IsA(kmldom.Type_NetworkLink):
|
||||
self.__name = 'Unnamed NetworkLink'
|
||||
else:
|
||||
self.__name = 'Unknown Feature'
|
||||
|
||||
def GetText(self):
|
||||
return self.__name
|
||||
|
||||
def GetSubList(self):
|
||||
container = kmldom.AsContainer(self.__element)
|
||||
if container:
|
||||
size = container.get_feature_array_size()
|
||||
if size == 0: return
|
||||
child_list = []
|
||||
for i in range(container.get_feature_array_size()):
|
||||
child_list.append(container.get_feature_array_at(i))
|
||||
children = [DomTreeItem(child) for child in child_list]
|
||||
return children
|
||||
|
||||
def IsExpandable(self):
|
||||
container = kmldom.AsContainer(self.__element)
|
||||
if container:
|
||||
return container.get_feature_array_size() > 0
|
||||
return False
|
||||
|
||||
|
||||
class DomViewer:
|
||||
def __init__(self, root):
|
||||
self.__root = root
|
||||
self.__yscrollbar = Scrollbar(self.__root)
|
||||
self.__yscrollbar.pack(side=RIGHT, fill=Y)
|
||||
self.__canvas = Canvas(self.__root, yscrollcommand=self.__yscrollbar.set)
|
||||
self.__canvas.pack(fill=BOTH, expand=YES)
|
||||
self.__yscrollbar.config(command=self.__canvas.yview)
|
||||
self.__filetypes = [('KML or KMZ files', '*.km*')]
|
||||
self.__CreateMenus()
|
||||
|
||||
def __CreateMenus(self):
|
||||
self.__app_menu = Menu(self.__root)
|
||||
self.__root.config(menu=self.__app_menu)
|
||||
self.__filemenu = Menu(self.__app_menu)
|
||||
self.__app_menu.add_cascade(label='File', menu=self.__filemenu)
|
||||
self.__filemenu.add_command(label='Open File...', command=self.__OpenFile)
|
||||
self.__filemenu.add_command(label='Open URL...', command=self.__OpenURL)
|
||||
self.__filemenu.add_command(label='Quit', command=self.__Quit)
|
||||
|
||||
def __SetDom(self, dom):
|
||||
item = DomTreeItem(dom)
|
||||
node = TreeNode(self.__canvas, None, item)
|
||||
node.update()
|
||||
node.expand()
|
||||
|
||||
def __GetRootFeature(self, element):
|
||||
kml = kmldom.AsKml(element)
|
||||
if kml:
|
||||
if kml.has_feature():
|
||||
return kml.get_feature()
|
||||
else:
|
||||
return None
|
||||
feature = kmldom.AsFeature(element)
|
||||
if feature:
|
||||
return feature
|
||||
return None
|
||||
|
||||
def __ReadKmlFromKmz(self, filename):
|
||||
if not zipfile.is_zipfile(filename):
|
||||
showwarning('Error', '%s is not a valid KMZ file' % filename)
|
||||
return None
|
||||
zfile = zipfile.ZipFile(filename, 'r')
|
||||
if 'doc.kml' in zfile.namelist():
|
||||
kml = zfile.read('doc.kml')
|
||||
else:
|
||||
kml = zfile.read(zfile.namelist()[0])
|
||||
if not kml:
|
||||
showwarning('Error', 'Failed reading KML from KMZ')
|
||||
return None
|
||||
return kml
|
||||
|
||||
def LoadFile(self, filename):
|
||||
# Public, can be called indirectly from command line.
|
||||
if zipfile.is_zipfile(filename):
|
||||
kml = self.__ReadKmlFromKmz(filename)
|
||||
else:
|
||||
kml = open(filename).read() # consume the entire file
|
||||
dom = self.__GetRootFeature(kmldom.ParseKml(kml))
|
||||
if dom is None:
|
||||
showwarning('Bad KML', 'The KML data could not be parsed')
|
||||
return
|
||||
self.__SetDom(dom)
|
||||
|
||||
def __OpenFile(self):
|
||||
f = askopenfilename(parent=self.__root, filetypes=self.__filetypes)
|
||||
if not f:
|
||||
return
|
||||
try:
|
||||
self.LoadFile(f)
|
||||
except IOError:
|
||||
showwarning('OpenFile', 'Cannot open the file')
|
||||
return
|
||||
|
||||
def LoadUrl(self, url):
|
||||
# Public, can be called indirectly from command line.
|
||||
response = urllib2.urlopen(url).read()
|
||||
(fd, name) = tempfile.mkstemp()
|
||||
os.write(fd, response)
|
||||
os.close(fd)
|
||||
self.LoadFile(name)
|
||||
os.unlink(name)
|
||||
|
||||
def __OpenURL(self):
|
||||
f = askstring('Open URL', 'URL', parent=self.__root,
|
||||
initialvalue='http://')
|
||||
if not f:
|
||||
return
|
||||
try:
|
||||
self.LoadUrl(f)
|
||||
except:
|
||||
showwarning('OpenUrl', 'Cannot open the URL: %s' %f)
|
||||
return
|
||||
|
||||
def __Quit(self, event=None):
|
||||
self.__root.quit()
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) > 2:
|
||||
print 'usage: %s kmlfile' % argv[0]
|
||||
sys.exit(1)
|
||||
root = Tk()
|
||||
app = DomViewer(root)
|
||||
if (len(argv) == 2):
|
||||
if argv[1].startswith('http://'):
|
||||
try: app.LoadUrl(argv[1])
|
||||
except: pass
|
||||
else:
|
||||
try: app.LoadFile(argv[1])
|
||||
except: pass
|
||||
root.mainloop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv)
|
|
@ -0,0 +1,64 @@
|
|||
build_example(
|
||||
NAME balloonwalker
|
||||
DEPENDS kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME clone
|
||||
DEPENDS kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME csv2kml
|
||||
DEPENDS kmlconvenience)
|
||||
|
||||
build_example(
|
||||
NAME csvinfo
|
||||
DEPENDS kmlconvenience)
|
||||
|
||||
build_example(
|
||||
NAME import
|
||||
DEPENDS kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME inlinestyles
|
||||
DEPENDS kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME kmlfile
|
||||
DEPENDS kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME kml2kmz
|
||||
DEPENDS kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME kmzchecklinks
|
||||
DEPENDS kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME oldschema
|
||||
DEPENDS kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME parsebig
|
||||
DEPENDS kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME printstyle
|
||||
DEPENDS kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME change
|
||||
DEPENDS kmlconvenience)
|
||||
|
||||
build_example(
|
||||
NAME splitstyles
|
||||
DEPENDS kmlconvenience)
|
||||
|
||||
build_example(
|
||||
NAME streamkml
|
||||
DEPENDS kmlconvenience)
|
||||
|
||||
if(INSTALL_EXAMPLES)
|
||||
file(GLOB eg_files "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
|
||||
install(FILES ${eg_files} DESTINATION examples/engine)
|
||||
endif(INSTALL_EXAMPLES)
|
|
@ -0,0 +1,102 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This example program that takes as its only argument a KML or KMZ file,
|
||||
// then walks through all contained Features, computing the markup required
|
||||
// to display the description balloon for each feature.
|
||||
|
||||
#include <iostream>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
using kmldom::BalloonStylePtr;
|
||||
using kmldom::DocumentPtr;
|
||||
using kmldom::ElementPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmldom::SerializePretty;
|
||||
using kmldom::SnippetPtr;
|
||||
using kmldom::StylePtr;
|
||||
using kmlengine::CreateBalloonText;
|
||||
using kmlengine::FeatureVisitor;
|
||||
using kmlengine::GetRootFeature;
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
using kmlengine::VisitFeatureHierarchy;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
// The FeatureVisitor class implements the mechanism to walk a Feature
|
||||
// hierarchy. This subclass calls CreateBalloonText on each Feature and prints
|
||||
// the composited text to stdout.
|
||||
class FeatureBalloonPrinter : public FeatureVisitor {
|
||||
public:
|
||||
FeatureBalloonPrinter(const KmlFilePtr& kml_file) :
|
||||
kml_file_(kml_file) {}
|
||||
// The callback from VisitFeatureHierarchy.
|
||||
virtual void VisitFeature(const kmldom::FeaturePtr& f) {
|
||||
std::string fname = f->has_name() ? f->get_name() : "Unnamed feature";
|
||||
cout << "Feature balloon text for " << fname << endl;
|
||||
cout << CreateBalloonText(kml_file_, f) << endl << endl;
|
||||
}
|
||||
private:
|
||||
const KmlFilePtr kml_file_;
|
||||
};
|
||||
|
||||
void VisitFeatureBalloons(const KmlFilePtr& kml_file) {
|
||||
FeatureBalloonPrinter feature_balloon_printer(kml_file);
|
||||
VisitFeatureHierarchy(GetRootFeature(kml_file->get_root()),
|
||||
feature_balloon_printer);
|
||||
}
|
||||
|
||||
int HandleFile(const char* filename) {
|
||||
std::string file_data;
|
||||
if (!kmlbase::File::ReadFileToString(filename, &file_data)) {
|
||||
cerr << "error: read of " << filename << " failed" << endl;
|
||||
return 1;
|
||||
}
|
||||
std::string errors;
|
||||
KmlFilePtr kml_file = KmlFile::CreateFromParse(file_data, &errors);
|
||||
if (!kml_file || !errors.empty()) {
|
||||
cerr << "parse failed: " << errors << endl;;
|
||||
return 1;
|
||||
}
|
||||
|
||||
VisitFeatureBalloons(kml_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "usage: " << argv[0] << " kmlfile" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return HandleFile(argv[1]);
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program shows basic ProcessUpdate() with <Change>.
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
using kmldom::ChangePtr;
|
||||
using kmldom::FolderPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmldom::UpdatePtr;
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
|
||||
static void HelloUpdateChange() {
|
||||
// This is the same KML as in the kmlfile.cc example.
|
||||
KmlFactory* kml_factory = KmlFactory::GetFactory();
|
||||
FolderPtr folder = kml_factory->CreateFolder();
|
||||
folder->set_id("f0");
|
||||
folder->set_name("Folder 0");
|
||||
PlacemarkPtr placemark = kml_factory->CreatePlacemark();
|
||||
placemark->set_id("pm0");
|
||||
placemark->set_name("Placemark 0");
|
||||
folder->add_feature(placemark);
|
||||
placemark = kml_factory->CreatePlacemark();
|
||||
placemark->set_id("pm1");
|
||||
placemark->set_name("Placemark 1");
|
||||
folder->add_feature(placemark);
|
||||
KmlPtr kml = kml_factory->CreateKml();
|
||||
kml->set_feature(folder);
|
||||
|
||||
// Importing to a KmlFile creates an internal database of object id mappings.
|
||||
KmlFilePtr kml_file = KmlFile::CreateFromImport(kml);
|
||||
|
||||
ChangePtr change = kml_factory->CreateChange();
|
||||
placemark = kmlconvenience::CreatePointPlacemark("new name", 38, -120);
|
||||
placemark->set_targetid("pm0");
|
||||
change->add_object(placemark);
|
||||
UpdatePtr update = kml_factory->CreateUpdate();
|
||||
update->add_updateoperation(change);
|
||||
|
||||
kmlengine::ProcessUpdate(update, kml_file);
|
||||
|
||||
std::string xml;
|
||||
kml_file->SerializeToString(&xml);
|
||||
std::cout << xml;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
HelloUpdateChange();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program makes some basic use of the KML Engine Clone() function.
|
||||
// Since element is shared in XML the Clone() function provides away to use the
|
||||
// same element data with multiple parents. Note that Clone() is a "deep"
|
||||
// clone: all simple and complex elements are cloned.
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
// This function creates a Region with a LatLonAltBox of the specified bounds
|
||||
// and a Lod with the specified minLodPixels.
|
||||
kmldom::RegionPtr CreateRegionLatLonAltBoxLod(double north, double south,
|
||||
double east, double west,
|
||||
double minlodpixels) {
|
||||
kmldom::KmlFactory* factory = kmldom::KmlFactory::GetFactory();
|
||||
kmldom::LatLonAltBoxPtr latlonaltbox = factory->CreateLatLonAltBox();
|
||||
latlonaltbox->set_north(north);
|
||||
latlonaltbox->set_south(south);
|
||||
latlonaltbox->set_east(east);
|
||||
latlonaltbox->set_west(west);
|
||||
kmldom::LodPtr lod = factory->CreateLod();
|
||||
lod->set_minlodpixels(minlodpixels);
|
||||
kmldom::RegionPtr region = factory->CreateRegion();
|
||||
region->set_latlonaltbox(latlonaltbox);
|
||||
region->set_lod(lod);
|
||||
return region;
|
||||
}
|
||||
|
||||
void HelloClone() {
|
||||
kmldom::KmlFactory* factory = kmldom::KmlFactory::GetFactory();
|
||||
|
||||
// Create a Container and some Features.
|
||||
kmldom::FolderPtr folder = factory->CreateFolder();
|
||||
kmldom::PlacemarkPtr pm0 = factory->CreatePlacemark();
|
||||
kmldom::PlacemarkPtr pm1 = factory->CreatePlacemark();
|
||||
|
||||
// Create a Region with LatLonAltBox and Lod.
|
||||
kmldom::RegionPtr region = CreateRegionLatLonAltBoxLod(1, 2, 3, 4, 100);
|
||||
|
||||
// Create a clone of this Region for each Placemark.
|
||||
pm0->set_region(kmldom::AsRegion(kmlengine::Clone(region)));
|
||||
pm1->set_region(kmldom::AsRegion(kmlengine::Clone(region)));
|
||||
folder->add_feature(pm0);
|
||||
folder->add_feature(pm1);
|
||||
|
||||
// Print the resulting XML.
|
||||
std::cout << kmldom::SerializePretty(folder);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
HelloClone();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This creates a KML file from a CSV file whose first row is a schema such as:
|
||||
// name,latitude,longitude,description,a,b,c
|
||||
// And each of whose lines look like:
|
||||
// hello,37.1,-111.123,how are you,1,2,3
|
||||
// A Point Placemark is created for each line in the CSV file. This example
|
||||
// prints an error for and drops each line not exactly matching the schema.
|
||||
// For very very large CSV files see: examples/regionator/csvregionator.cc.
|
||||
// For very very large KML files see: streamkml.cc.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/base/csv_splitter.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/base/string_util.h"
|
||||
#include "kml/convenience/csv_parser.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
using kmlbase::File;
|
||||
using kmlconvenience::CreatePointPlacemark;
|
||||
using kmlconvenience::CsvParser;
|
||||
using kmlconvenience::CsvParserHandler;
|
||||
using kmlconvenience::CsvParserStatus;
|
||||
using kmldom::ContainerPtr;
|
||||
using kmldom::FolderPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
|
||||
// This CsvParserHandler saves all "OK" Placemarks to the passed Container.
|
||||
class ContainerSaver : public CsvParserHandler {
|
||||
public:
|
||||
ContainerSaver(ContainerPtr container)
|
||||
: container_(container) {
|
||||
}
|
||||
|
||||
virtual bool HandleLine(int line, CsvParserStatus status, PlacemarkPtr p) {
|
||||
if (status == kmlconvenience::CSV_PARSER_STATUS_OK) {
|
||||
container_->add_feature(p);
|
||||
} else {
|
||||
if (line == 1 && status == kmlconvenience::CSV_PARSER_STATUS_NO_LAT_LON) {
|
||||
std::cerr << "Schema line must have both \"latitude\" and "
|
||||
<< "\"longitude\"." << std::endl;
|
||||
} else {
|
||||
std::cerr << "Error on line " << line << std::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
ContainerPtr container_;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "usage: " << argv[0] << " input.csv output.kml" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string csv_data;
|
||||
if (!kmlbase::File::ReadFileToString(argv[1], &csv_data)) {
|
||||
std::cerr << "Read failed: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
kmlbase::CsvSplitter csv_splitter(csv_data);
|
||||
|
||||
// Create a <Folder> and a ContainerSaver to write to it.
|
||||
FolderPtr folder = kmldom::KmlFactory::GetFactory()->CreateFolder();
|
||||
ContainerSaver container_saver(folder);
|
||||
|
||||
// Call the CsvParser in strict mode to convert each line of CSV data into
|
||||
// a Placemark saved into the supplied Folder.
|
||||
if (!kmlconvenience::CsvParser::ParseCsv(&csv_splitter, &container_saver)) {
|
||||
std::cerr << "ParseCsv failed: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Feature count " << folder->get_feature_array_size()
|
||||
<< std::endl;
|
||||
|
||||
// Import to kmlengine::KmlFile to get a nice xml header and xml namespace on
|
||||
// the root element.
|
||||
kmldom::KmlPtr kml = kmldom::KmlFactory::GetFactory()->CreateKml();
|
||||
kml->set_feature(folder);
|
||||
KmlFilePtr kml_file = KmlFile::CreateFromImport(kml);
|
||||
std::string xml;
|
||||
kml_file->SerializeToString(&xml);
|
||||
return File::WriteStringToFile(xml, argv[2]) ? 1 : 0;
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
// Copyright 2010, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program parses the given CSV file and prints out some basic info.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/base/csv_splitter.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/base/string_util.h"
|
||||
#include "kml/convenience/csv_parser.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/dom.h"
|
||||
|
||||
using kmlbase::File;
|
||||
using kmlconvenience::CreatePointPlacemark;
|
||||
using kmlconvenience::CsvParser;
|
||||
using kmlconvenience::CsvParserHandler;
|
||||
using kmlconvenience::CsvParserStatus;
|
||||
using kmldom::ContainerPtr;
|
||||
using kmldom::FolderPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
|
||||
// This CsvParserHandler saves all "OK" Placemarks to the passed Container.
|
||||
class CsvInfo : public CsvParserHandler {
|
||||
public:
|
||||
CsvInfo()
|
||||
: good_(0),
|
||||
bad_(0) {
|
||||
}
|
||||
|
||||
virtual bool HandleLine(int line, CsvParserStatus status, PlacemarkPtr p) {
|
||||
if (status == kmlconvenience::CSV_PARSER_STATUS_OK) {
|
||||
++good_;
|
||||
} else {
|
||||
++bad_;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int get_good() const {
|
||||
return good_;
|
||||
}
|
||||
unsigned int get_bad() const {
|
||||
return bad_;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int good_;
|
||||
unsigned int bad_;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "usage: " << argv[0] << "input.csv" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string csv_data;
|
||||
if (!kmlbase::File::ReadFileToString(argv[1], &csv_data)) {
|
||||
std::cerr << "Read failed: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
kmlbase::CsvSplitter csv_splitter(csv_data);
|
||||
|
||||
CsvInfo csv_info;
|
||||
|
||||
// Call the CsvParser in strict mode to convert each line of CSV data into
|
||||
// a Placemark saved into the supplied Folder.
|
||||
if (!kmlconvenience::CsvParser::ParseCsv(&csv_splitter, &csv_info)) {
|
||||
std::cerr << "ParseCsv failed: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Good lines " << csv_info.get_good() << std::endl;
|
||||
std::cout << "Bad lines " << csv_info.get_bad() << std::endl;
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program shows basic use of KML Engine KmlFile::CreateFromImport().
|
||||
// KmlFile's GetObjectById() provides an efficient and convenient means to find
|
||||
// an element by its XML ID.
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
using kmldom::FolderPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
|
||||
static void HelloKmlFileCreateFromImport() {
|
||||
// This is the same KML as in the kmlfile.cc example.
|
||||
KmlFactory* kml_factory = KmlFactory::GetFactory();
|
||||
FolderPtr folder = kml_factory->CreateFolder();
|
||||
folder->set_id("f0");
|
||||
folder->set_name("Folder 0");
|
||||
PlacemarkPtr placemark = kml_factory->CreatePlacemark();
|
||||
placemark->set_id("pm0");
|
||||
placemark->set_name("Placemark 0");
|
||||
folder->add_feature(placemark);
|
||||
placemark = kml_factory->CreatePlacemark();
|
||||
placemark->set_id("pm1");
|
||||
placemark->set_name("Placemark 1");
|
||||
folder->add_feature(placemark);
|
||||
KmlPtr kml = kml_factory->CreateKml();
|
||||
kml->set_feature(folder);
|
||||
|
||||
// Importing to a KmlFile creates an internal database of object id mappings.
|
||||
KmlFilePtr kml_file = KmlFile::CreateFromImport(kml);
|
||||
|
||||
// Access the 3 Features by their XML Id. Note that GetObjectById() returns
|
||||
// a ObjectPtr, hence the use of the cast to access <name>.
|
||||
FolderPtr folder0 = AsFolder(kml_file->GetObjectById("f0"));
|
||||
std::cout << "Folder 0 name: " << folder0->get_name() << std::endl;
|
||||
PlacemarkPtr placemark0 = AsPlacemark(kml_file->GetObjectById("pm0"));
|
||||
std::cout << "Placemark 0 name: " << placemark0->get_name() << std::endl;
|
||||
PlacemarkPtr placemark1 = AsPlacemark(kml_file->GetObjectById("pm1"));
|
||||
std::cout << "Placemark 1 name: " << placemark1->get_name() << std::endl;
|
||||
|
||||
// KmlFile's serialize defaults to the OGC KML 2.2 XML namespace and adds
|
||||
// an XML header specifying UTF-8 encoding.
|
||||
std::string xml;
|
||||
kml_file->SerializeToString(&xml);
|
||||
std::cout << xml;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
HelloKmlFileCreateFromImport();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program shows use of the kmlengine::InlineStyles function which parses
|
||||
// a KML file inlining shared style selectors to features from the root
|
||||
// <Document>. See kml/engine/style_inliner.h for details.
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
bool InlineStyles(const char* input_filename, const char* output_filename) {
|
||||
std::string kml_input;
|
||||
if (!kmlbase::File::ReadFileToString(input_filename, &kml_input)) {
|
||||
std::cerr << "read failed: " << input_filename << std::cerr;
|
||||
return false;
|
||||
}
|
||||
std::string errors;
|
||||
kmldom::ElementPtr root = kmlengine::InlineStyles(kml_input, &errors);
|
||||
if (!root) {
|
||||
std::cerr << "parse failed: " << input_filename << std::cerr;
|
||||
std::cerr << "parse failed: " << errors << std::cerr;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string kml_output = kmldom::SerializePretty(root);
|
||||
if (!kmlbase::File::WriteStringToFile(kml_output, output_filename)) {
|
||||
std::cerr << "write failed: " << output_filename << std::cerr;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "usage: " << argv[0] << " input.kml output.kml" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return InlineStyles(argv[1], argv[2]) ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program uses KmzFile::CreateFromKmlFilepath to create a KMZ archive
|
||||
// from a KML file. The file's resources are bundled into the archive if their
|
||||
// location is relative to the directory in which the KML file is located.
|
||||
// A listing of the generated archive is printed at the end.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/engine.h"
|
||||
|
||||
using kmlbase::StringVector;
|
||||
using kmlengine::KmzFile;
|
||||
using kmlengine::KmzFilePtr;
|
||||
|
||||
static void ListFiles(const std::string& kmz_filepath) {
|
||||
KmzFilePtr kmz(KmzFile::OpenFromFile(kmz_filepath.c_str()));
|
||||
if (!kmz) {
|
||||
return;
|
||||
}
|
||||
StringVector list;
|
||||
kmz->List(&list);
|
||||
StringVector::const_iterator itr;
|
||||
std::cout << "contents:" << std::endl;
|
||||
for (itr = list.begin(); itr != list.end(); ++itr) {
|
||||
std::cout << " " << *itr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "usage: " << argv[0] << " input.kml output.kmz" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const std::string kml_filepath = argv[1];
|
||||
const std::string kmz_filepath = argv[2];
|
||||
|
||||
if (!KmzFile::CreateFromKmlFilepath(kml_filepath, kmz_filepath)) {
|
||||
std::cerr << "could not create KMZ file from " << kml_filepath << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "wrote " << kmz_filepath << std::endl;
|
||||
ListFiles(kmz_filepath);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program makes some basic use of the KML Engine KmlFile class.
|
||||
// KmlFile's GetObjectById() provides an efficient and convenient means to fine
|
||||
// an element by its XML ID.
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
void HelloKmlFile() {
|
||||
const std::string kKml =
|
||||
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">"
|
||||
"<Folder id=\"f0\">"
|
||||
"<name>Folder 0</name>"
|
||||
"<Placemark id=\"pm0\">"
|
||||
"<name>Placemark 0</name>"
|
||||
"</Placemark>"
|
||||
"<Placemark id=\"pm1\">"
|
||||
"<name>Placemark 1</name>"
|
||||
"</Placemark>"
|
||||
"</Folder>"
|
||||
"</kml>";
|
||||
|
||||
// Parsing into a KmlFile creates an internal database of object id mappings.
|
||||
kmlengine::KmlFilePtr kml_file = kmlengine::KmlFile::CreateFromParse(kKml,
|
||||
NULL);
|
||||
|
||||
// Access the 3 Features by their XML Id. Note that GetObjectById() returns
|
||||
// a ObjectPtr, hence the use of the cast to access <name>.
|
||||
kmldom::FolderPtr folder0 = AsFolder(kml_file->GetObjectById("f0"));
|
||||
std::cout << "Folder 0 name: " << folder0->get_name() << std::endl;
|
||||
kmldom::PlacemarkPtr placemark0 = AsPlacemark(kml_file->GetObjectById("pm0"));
|
||||
std::cout << "Placemark 0 name: " << placemark0->get_name() << std::endl;
|
||||
kmldom::PlacemarkPtr placemark1 = AsPlacemark(kml_file->GetObjectById("pm1"));
|
||||
std::cout << "Placemark 1 name: " << placemark1->get_name() << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
HelloKmlFile();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program checks the KMZ archive for all files the KML references.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
using boost::scoped_ptr;
|
||||
using kmlengine::Href;
|
||||
using kmlengine::KmzFile;
|
||||
|
||||
int PrintAndCheckLinks(const char* kmz_filename) {
|
||||
// Open the KMZ file.
|
||||
scoped_ptr<KmzFile> kmz_file(KmzFile::OpenFromFile(kmz_filename));
|
||||
if (!kmz_file.get()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Dig out the KML.
|
||||
std::string kml;
|
||||
if (!kmz_file->ReadKml(&kml)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the links.
|
||||
// TODO engine support for links in <description> and <BalloonStyle><text>
|
||||
kmlengine::href_vector_t href_vector;
|
||||
if (!kmlengine::GetLinks(kml, &href_vector)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO Model/Alias/targetHref is relative to Model/Link/href.
|
||||
// TODO if Model/Link/href="dir/model.kml" then textures/foo.jpg is
|
||||
// TODO access with Model/ResourceMap/Alias/targetHref="../textures/foo.jpg"
|
||||
|
||||
// Try to access each relative link within the KMZ.
|
||||
int ret = 0;
|
||||
for (size_t i = 0; i < href_vector.size(); ++i) {
|
||||
std::cout << href_vector[i] << " ... ";
|
||||
Href href(href_vector[i]);
|
||||
if (href.IsRelativePath()) {
|
||||
std::string content;
|
||||
if (!kmz_file->ReadFile(href.get_path().c_str(), &content)) {
|
||||
std::cout << "NO";
|
||||
ret = -1;
|
||||
} else {
|
||||
std::cout << "yes";
|
||||
}
|
||||
} else if (href.IsFragmentOnly()) {
|
||||
std::cout << "(fragment only)";
|
||||
} else {
|
||||
std::cout << "(absolute)";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "usage: " << argv[0] << " file.kmz" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
return PrintAndCheckLinks(argv[1]);
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This example uses the kmlengine::SchemaParserObserver and
|
||||
// kmlengine::OldSchemaParserObserver to convert "old-style" <Schema> to valid
|
||||
// OGC KML 2.2. See kml/engine/parse_old_schema.h for details.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/engine/old_schema_parser_observer.h"
|
||||
#include "kml/engine/schema_parser_observer.h"
|
||||
#include "kml/engine/engine_types.h"
|
||||
#include "kml/base/file.h"
|
||||
|
||||
using kmlengine::KmzFile;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cout << "usage: " << argv[0] << " kmlfile" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read the file.
|
||||
std::string file_data;
|
||||
if (!kmlbase::File::ReadFileToString(argv[1], &file_data)) {
|
||||
cout << argv[1] << " read failed" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// If the file was KMZ, extract the KML file.
|
||||
std::string kml;
|
||||
if (KmzFile::IsKmz(file_data)) {
|
||||
boost::scoped_ptr<KmzFile> kmz_file(KmzFile::OpenFromString(argv[1]));
|
||||
if (!kmz_file.get()) {
|
||||
cout << "Failed opening KMZ file" << endl;
|
||||
return 1;
|
||||
}
|
||||
if (!kmz_file->ReadKml(&kml)) {
|
||||
cout << "Failed to read KML from KMZ" << endl;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
kml = file_data;
|
||||
}
|
||||
|
||||
// This holds mappings from <Schema name="..."> to SchemaPtr.
|
||||
kmlengine::SchemaNameMap schema_name_map;
|
||||
// This finds all <Schema>'s in the parse and saves them in schema_name_map.
|
||||
kmlengine::SchemaParserObserver schema_parser_observer(&schema_name_map);
|
||||
// This uses mappings in schema_name_map to convert each "old-style" <Schema>
|
||||
// instances into an OGC KML 2.2 <Placemark>.
|
||||
kmlengine::OldSchemaParserObserver old_schema_parser_observer(
|
||||
schema_name_map);
|
||||
// Configure the parser with the two observers.
|
||||
kmldom::Parser parser;
|
||||
parser.AddObserver(&schema_parser_observer);
|
||||
parser.AddObserver(&old_schema_parser_observer);
|
||||
std::string errors;
|
||||
kmldom::ElementPtr root = parser.Parse(kml, &errors);
|
||||
if (!root) {
|
||||
cout << errors << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
cout << kmldom::SerializePretty(root);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program shows basic use of streamed parsing.
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
using kmldom::FolderPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmlengine::KmlStream;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
static int HelloKmlStreamCreateFromIstream(const char* filename) {
|
||||
std::ifstream input_file(filename, std::ios_base::in|std::ios_base::binary);
|
||||
if (!input_file.is_open() || !input_file.good()) {
|
||||
cerr << "open failed: " << filename << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string errors;
|
||||
boost::scoped_ptr<KmlStream> kml_stream(
|
||||
KmlStream::ParseFromIstream(&input_file, &errors, NULL));
|
||||
if (!kml_stream.get()) {
|
||||
cerr << "KmlStream::CreateFromIstream failed: " << filename << endl;
|
||||
if (!errors.empty()) {
|
||||
cerr << errors << endl;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cerr << "usage: " << argv[0] << "big.kml" << endl;
|
||||
return 1;
|
||||
}
|
||||
return HelloKmlStreamCreateFromIstream(argv[1]);
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program makes some basic use of the KML Engine CreateResolvedStyle()
|
||||
// function. For example:
|
||||
// printstyle ../../../examples/kml/polygons2d.kml pm300
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/base/file.h"
|
||||
|
||||
// This prints out the normal <Style> for the feature of the given id in the
|
||||
// given KML file.
|
||||
void HelloCreateResolvedStyle(const std::string& kml_filename,
|
||||
const std::string& id) {
|
||||
// Read the KML file.
|
||||
std::string kml_content;
|
||||
if (!kmlbase::File::ReadFileToString(kml_filename, &kml_content)) {
|
||||
std::cerr << "read error: " << kml_filename << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse using KmlFile.
|
||||
std::string errors;
|
||||
kmlengine::KmlFilePtr kml_file =
|
||||
kmlengine::KmlFile::CreateFromParse(kml_content, &errors);
|
||||
if (!kml_file) {
|
||||
std::cerr << errors;
|
||||
return;
|
||||
}
|
||||
|
||||
// Look up the Feature
|
||||
kmldom::FeaturePtr feature = kmldom::AsFeature(kml_file->GetObjectById(id));
|
||||
if (!feature) {
|
||||
std::cerr << "no feature with id: " << id << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a resolved style for the Feature and print it.
|
||||
kmldom::StylePtr style = CreateResolvedStyle(feature, kml_file,
|
||||
kmldom::STYLESTATE_NORMAL);
|
||||
std::cout << kmldom::SerializePretty(style);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "usage: " << argv[0] << "kmlfile feature-id" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
HelloCreateResolvedStyle(argv[1], argv[2]);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,225 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="printstyle"
|
||||
ProjectGUID="{08F2DC19-28A2-4048-8706-9D8F03F659DA}"
|
||||
RootNamespace="printstyle"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\third_party\boost_1_34_1;..\..\src;..\..\third_party\uriparser-0.7.1\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="libkmlbase.lib libkmldom.lib libkmlengine.lib libexpat.lib minizip.lib zlib.lib uriparser-debug.lib"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="C:\Program Files\Expat 2.0.1\Bin;..\..\debug;..\..\third_party\zlib-1.2.3.win32\lib;..\..\third_party\uriparser-0.7.1.win32\debug"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\third_party\boost_1_34_1;..\..\src;..\..\third_party\uriparser-0.7.1\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="libkmlbase.lib libkmldom.lib libkmlengine.lib libexpat.lib minizip.lib zlib.lib uriparser-release.lib"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="C:\Program Files\Expat 2.0.1\Bin;..\..\release;..\..\third_party\zlib-1.2.3.win32\lib;..\..\third_party\uriparser-0.7.1.win32\release"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath="printstyle.cc"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program shows use of the kmlengine::SplitStyles function which parses
|
||||
// a KML file splitting inlined style selectors from features to the root
|
||||
// <Document>. See kml/engine/style_splitter.h for details.
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
bool SplitStyles(const char* input_filename, const char* output_filename) {
|
||||
std::string kml_input;
|
||||
if (!kmlbase::File::ReadFileToString(input_filename, &kml_input)) {
|
||||
std::cerr << "read failed: " << input_filename << std::cerr;
|
||||
return false;
|
||||
}
|
||||
std::string errors;
|
||||
kmldom::ElementPtr root = kmlengine::SplitStyles(kml_input, &errors);
|
||||
if (!root) {
|
||||
std::cerr << "parse failed: " << input_filename << std::cerr;
|
||||
std::cerr << "parse failed: " << errors << std::cerr;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string kml_output = kmldom::SerializePretty(root);
|
||||
if (!kmlbase::File::WriteStringToFile(kml_output, output_filename)) {
|
||||
std::cerr << "write failed: " << output_filename << std::cerr;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "usage: " << argv[0] << " input.kml output.kml" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return SplitStyles(argv[1], argv[2]) ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This example shows how KmlStream is used with a ParserObserver. Given that
|
||||
// the ParserObserver inhibits adding Features to the DOM this program can be
|
||||
// used to scan extremely large files such as those where DOM representation
|
||||
// would exceed available memmory.
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
using kmldom::AsFeature;
|
||||
using kmldom::ElementPtr;
|
||||
using kmldom::FeaturePtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::LatLonBoxPtr;
|
||||
using kmldom::SerializePretty;
|
||||
using kmlengine::Bbox;
|
||||
using kmlengine::GetFeatureLatLon;
|
||||
using kmlengine::KmlStream;
|
||||
|
||||
// This ParserObserver inhibits adding of any Feature to the DOM. A bounding
|
||||
// box of all features is maintained.
|
||||
class FeatureStreamer : public kmldom::ParserObserver {
|
||||
public:
|
||||
FeatureStreamer()
|
||||
: feature_count_(0) {
|
||||
}
|
||||
|
||||
// ParserObserver::EndElement()
|
||||
virtual bool EndElement(const ElementPtr& parent, const ElementPtr& child) {
|
||||
if (FeaturePtr feature = AsFeature(child)) {
|
||||
// This is roughly 1hz in a 2 ghz MacBook.
|
||||
if (++feature_count_ % 10000 == 0 ) {
|
||||
std::cout << feature_count_ << " " << feature->get_name();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
GetFeatureBounds(feature, &bbox_);
|
||||
// Do not add this feature to the DOM (note that this discards both
|
||||
// <Documents> and <Folders>).
|
||||
return false;
|
||||
}
|
||||
// Preserve all other parent-child relationships (such as those _within_
|
||||
// a feature such as the Point child of Placemark and coordinates child
|
||||
// of Point as expected in GetFeatureLatLon).
|
||||
return true;
|
||||
}
|
||||
|
||||
const Bbox& get_bbox() const {
|
||||
return bbox_;
|
||||
}
|
||||
int get_feature_count() const {
|
||||
return feature_count_;
|
||||
}
|
||||
private:
|
||||
Bbox bbox_;
|
||||
int feature_count_;
|
||||
};
|
||||
|
||||
void StreamKml(std::istream* input) {
|
||||
FeatureStreamer feature_streamer;
|
||||
std::string errors;
|
||||
boost::scoped_ptr<KmlStream> kml_stream(
|
||||
KmlStream::ParseFromIstream(input, &errors, &feature_streamer));
|
||||
if (!kml_stream.get()) {
|
||||
std::cerr << "KmlStream error " << errors << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "Streamed parse completed, ";
|
||||
std::cout << feature_streamer.get_feature_count() << " features";
|
||||
std::cout << std::endl;
|
||||
|
||||
// Emit the bounding box as KML.
|
||||
KmlFactory* kml_factory = KmlFactory::GetFactory();
|
||||
LatLonBoxPtr llab = kml_factory->CreateLatLonBox();
|
||||
const Bbox& bbox = feature_streamer.get_bbox();
|
||||
llab->set_north(bbox.get_north());
|
||||
llab->set_south(bbox.get_south());
|
||||
llab->set_east(bbox.get_east());
|
||||
llab->set_west(bbox.get_west());
|
||||
std::cout << SerializePretty(llab);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "usage: " << argv[0] << " huge.kml" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
const char* filename = argv[1];
|
||||
std::ifstream input_file(filename, std::ios_base::in|std::ios_base::binary);
|
||||
if (!input_file.is_open() || !input_file.good()) {
|
||||
std::cerr << "open failed: " << filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
StreamKml(&input_file);
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "createkml", "helloworld\createkml.vcproj", "{2D08AB30-4254-479F-9EF0-67E5C1EE2E64}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "parsekml", "helloworld\parsekml.vcproj", "{5ADB0151-CD72-4260-9A4A-5C2FA7D53F72}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "prettykml", "helloworld\prettykml.vcproj", "{FC3E952B-9781-4DE5-A26B-A2D1DC8F9646}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sortplacemarks", "helloworld\sortplacemarks.vcproj", "{FCD0B93B-BBCE-452B-AE9D-D03427A04543}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "printstyle", "engine\printstyle.vcproj", "{08F2DC19-28A2-4048-8706-9D8F03F659DA}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "csvregionator", "regionator\csvregionator.vcproj", "{12044D18-00ED-4AA1-906E-48D5B12A877D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2D08AB30-4254-479F-9EF0-67E5C1EE2E64}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{2D08AB30-4254-479F-9EF0-67E5C1EE2E64}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{2D08AB30-4254-479F-9EF0-67E5C1EE2E64}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{2D08AB30-4254-479F-9EF0-67E5C1EE2E64}.Release|Win32.Build.0 = Release|Win32
|
||||
{5ADB0151-CD72-4260-9A4A-5C2FA7D53F72}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{5ADB0151-CD72-4260-9A4A-5C2FA7D53F72}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{5ADB0151-CD72-4260-9A4A-5C2FA7D53F72}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{5ADB0151-CD72-4260-9A4A-5C2FA7D53F72}.Release|Win32.Build.0 = Release|Win32
|
||||
{FC3E952B-9781-4DE5-A26B-A2D1DC8F9646}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{FC3E952B-9781-4DE5-A26B-A2D1DC8F9646}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{FC3E952B-9781-4DE5-A26B-A2D1DC8F9646}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{FC3E952B-9781-4DE5-A26B-A2D1DC8F9646}.Release|Win32.Build.0 = Release|Win32
|
||||
{FCD0B93B-BBCE-452B-AE9D-D03427A04543}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{FCD0B93B-BBCE-452B-AE9D-D03427A04543}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{FCD0B93B-BBCE-452B-AE9D-D03427A04543}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{FCD0B93B-BBCE-452B-AE9D-D03427A04543}.Release|Win32.Build.0 = Release|Win32
|
||||
{08F2DC19-28A2-4048-8706-9D8F03F659DA}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{08F2DC19-28A2-4048-8706-9D8F03F659DA}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{08F2DC19-28A2-4048-8706-9D8F03F659DA}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{08F2DC19-28A2-4048-8706-9D8F03F659DA}.Release|Win32.Build.0 = Release|Win32
|
||||
{12044D18-00ED-4AA1-906E-48D5B12A877D}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{12044D18-00ED-4AA1-906E-48D5B12A877D}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{12044D18-00ED-4AA1-906E-48D5B12A877D}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{12044D18-00ED-4AA1-906E-48D5B12A877D}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,13 @@
|
|||
# AM_CPPFLAGS = -I$(top_srcdir)/src \
|
||||
# -I$(top_srcdir)/third_party/boost_1_34_1
|
||||
# if GCC
|
||||
# AM_CXXFLAGS = -Wall -Werror -pedantic -Wno-long-long -fno-rtti
|
||||
# endif
|
||||
build_example(
|
||||
NAME gpxtracktokml
|
||||
DEPENDS kmlconvenience)
|
||||
|
||||
if(INSTALL_EXAMPLES)
|
||||
file(GLOB eg_files "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
|
||||
install(FILES ${eg_files} DESTINATION examples/gpx)
|
||||
endif(INSTALL_EXAMPLES)
|
|
@ -0,0 +1,258 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program converts a GPX track log to KML. Each GPX <trkpt> is converted
|
||||
// to a KML <Point> <Placemark> with <TimeStamp> and <ExtendedData>. All
|
||||
// other GPX elements are ignored. The <Placemark>'s are arranged in
|
||||
// <Folder>'s by date and "trip". Note that "trip" is not the same as the GPX
|
||||
// file <trk> or <trkseg>; "trip" is determined solely by point timestamp and
|
||||
// an internal threshold for determining when a new trip begins.
|
||||
|
||||
#include <time.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "kml/base/date_time.h"
|
||||
#include "kml/base/expat_parser.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/base/vec3.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/gpx_trk_pt_handler.h"
|
||||
#include "kml/dom.h"
|
||||
|
||||
using kmlbase::ExpatParser;
|
||||
using kmlbase::DateTime;
|
||||
using kmlbase::Vec3;
|
||||
using kmldom::ContainerPtr;
|
||||
using kmldom::FolderPtr;
|
||||
using kmldom::IconStylePtr;
|
||||
using kmldom::IconStyleIconPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::LabelStylePtr;
|
||||
using kmldom::ListStylePtr;
|
||||
using kmldom::PairPtr;
|
||||
using kmldom::PointPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmldom::TimeStampPtr;
|
||||
using kmldom::StylePtr;
|
||||
using kmldom::StyleMapPtr;
|
||||
|
||||
static const char kDotIcon[] =
|
||||
"http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png";
|
||||
|
||||
static const int kTripThreshold = 600; // 10 minutes.
|
||||
|
||||
static IconStylePtr CreateIconStyle(double scale) {
|
||||
KmlFactory* kml_factory = KmlFactory::GetFactory();
|
||||
IconStyleIconPtr icon = kml_factory->CreateIconStyleIcon();
|
||||
icon->set_href(kDotIcon);
|
||||
IconStylePtr icon_style = kml_factory->CreateIconStyle();
|
||||
icon_style->set_icon(icon);
|
||||
icon_style->set_scale(scale);
|
||||
return icon_style;
|
||||
}
|
||||
|
||||
static LabelStylePtr CreateLabelStyle(double scale) {
|
||||
LabelStylePtr label_style = KmlFactory::GetFactory()->CreateLabelStyle();
|
||||
label_style->set_scale(scale);
|
||||
return label_style;
|
||||
}
|
||||
|
||||
static PairPtr CreatePair(int style_state, double icon_scale) {
|
||||
KmlFactory* kml_factory = KmlFactory::GetFactory();
|
||||
PairPtr pair = kml_factory->CreatePair();
|
||||
pair->set_key(style_state);
|
||||
StylePtr style = kml_factory->CreateStyle();
|
||||
style->set_iconstyle(CreateIconStyle(icon_scale));
|
||||
// Hide the label in normal style state, visible in highlight.
|
||||
style->set_labelstyle(CreateLabelStyle(
|
||||
style_state == kmldom::STYLESTATE_NORMAL ? 0 : 1 ));
|
||||
pair->set_styleselector(style);
|
||||
return pair;
|
||||
}
|
||||
|
||||
static StylePtr CreateRadioFolder(const char* id) {
|
||||
KmlFactory* kml_factory = KmlFactory::GetFactory();
|
||||
ListStylePtr list_style = kml_factory->CreateListStyle();
|
||||
list_style->set_listitemtype(kmldom::LISTITEMTYPE_RADIOFOLDER);
|
||||
StylePtr style = kml_factory->CreateStyle();
|
||||
style->set_liststyle(list_style);
|
||||
style->set_id(id);
|
||||
return style;
|
||||
}
|
||||
|
||||
static StyleMapPtr CreateStyleMap(const char* id) {
|
||||
KmlFactory* kml_factory = KmlFactory::GetFactory();
|
||||
StyleMapPtr style_map = kml_factory->CreateStyleMap();
|
||||
style_map->set_id(id);
|
||||
style_map->add_pair(CreatePair(kmldom::STYLESTATE_NORMAL, 1.1));
|
||||
style_map->add_pair(CreatePair(kmldom::STYLESTATE_HIGHLIGHT, 1.3));
|
||||
return style_map;
|
||||
}
|
||||
|
||||
// Convert GPX <trkpt>'s to KML <Placemark>'s.
|
||||
// For example, this GPX <trkpt>:
|
||||
// <trkpt lat="-33.911973070" lon="18.422974152">
|
||||
// <ele>4.943848</ele>
|
||||
// <time>2008-10-11T14:55:41Z</time>
|
||||
// </trkpt>
|
||||
// ...is translated to this KML <Placemark>:
|
||||
// <Placemark>
|
||||
// <name>15:50:48</name>
|
||||
// <TimeStamp><when>2008-10-01T15:50:48Z</when></TimeStamp>
|
||||
// <ExtendedData>
|
||||
// <Data name="date"><value>2008-10-01</value></Data>
|
||||
// <Data name="time"><value>15:50:48</value></Data>
|
||||
// </ExtendedData>
|
||||
// <Point><coordinates>18.427167954,-33.911966113,0</coordinates></Point>
|
||||
// </Placemark>
|
||||
// There is a <Folder> for each day named in xsd:date format (YYYY-MM-DD) and
|
||||
// a sub-<Folder> within each day for each segment of <trkpt>'s. Note that
|
||||
// this is not the same as the GPX <trgseg>. Instead a threshold is used to
|
||||
// determine a break in a segment. (In practice a GPS unit may lose signal
|
||||
// for far longer than is represented in a <trkseg>). This threshold is
|
||||
// intended to represent a best guess for when one real-world trip ends and a
|
||||
// new one begins. This handler ignores all other elements in GPX.
|
||||
// TODO: Ideally each user-visible time is converted to the timezone of the
|
||||
// point.
|
||||
class TrkPtHandler : public kmlconvenience::GpxTrkPtHandler {
|
||||
public:
|
||||
// Create the TrkPtHandler with a KML Container into which all KML generated
|
||||
// here is appended. Each <trkpt> is saved as a <Point> <Placemark> whose
|
||||
// <styleUrl> is set to the given shared style.
|
||||
TrkPtHandler(ContainerPtr container, const char* point_style_id)
|
||||
: root_container_(container),
|
||||
point_style_id_(point_style_id),
|
||||
last_time_(0) {
|
||||
}
|
||||
|
||||
// This is called for each <trkpt>.
|
||||
// Create a <Point> <Placemark> at the location specified by Vec3 and give
|
||||
// it a <TimeStamp> based on when.
|
||||
virtual void HandlePoint(const kmlbase::Vec3& where,
|
||||
const std::string& when) {
|
||||
boost::scoped_ptr<DateTime> date_time(DateTime::Create(when));
|
||||
if (!date_time.get()) {
|
||||
std::cerr << "bad DateTime " << when << std::endl;
|
||||
return;
|
||||
}
|
||||
PointPtr point = kmlconvenience::CreatePointFromVec3(where);
|
||||
FolderPtr folder = ManageFolders(*date_time);
|
||||
folder->add_feature(kmlconvenience::CreatePointPlacemarkWithTimeStamp(
|
||||
point, *date_time, point_style_id_));
|
||||
}
|
||||
|
||||
private:
|
||||
// Create and/or return the folder for this DateTime. This method owns the
|
||||
// creation of the folder hierarchy. The first level of hierarchy is a
|
||||
// folder for each date within which is a folder for each "trip". It is
|
||||
// presumed that the DateTime's are presented to this method in time-order.
|
||||
FolderPtr ManageFolders(/*const*/ DateTime& date_time) {
|
||||
if (date_time.GetTimeT() - last_time_ > kTripThreshold) {
|
||||
// Threshold exceeded. Save trip and start a new folder.
|
||||
if (!date_folder_) { // First time around.
|
||||
date_folder_ = kmldom::KmlFactory::GetFactory()->CreateFolder();
|
||||
date_folder_->set_name(last_date_ = date_time.GetXsdDate());
|
||||
}
|
||||
date_folder_->add_feature(trip_folder_);
|
||||
trip_folder_ = kmldom::KmlFactory::GetFactory()->CreateFolder();
|
||||
trip_folder_->set_name(date_time.GetXsdTime());
|
||||
}
|
||||
last_time_ = date_time.GetTimeT();
|
||||
if (last_date_ != date_time.GetXsdDate()) {
|
||||
// Dawn. Save the previous day.
|
||||
root_container_->add_feature(date_folder_);
|
||||
date_folder_ = kmldom::KmlFactory::GetFactory()->CreateFolder();
|
||||
date_folder_->set_name(last_date_ = date_time.GetXsdDate());
|
||||
}
|
||||
return trip_folder_;
|
||||
}
|
||||
|
||||
ContainerPtr root_container_;
|
||||
const char* point_style_id_;
|
||||
FolderPtr date_folder_;
|
||||
FolderPtr trip_folder_;
|
||||
PointPtr point_;
|
||||
boost::scoped_ptr<DateTime> date_time_;
|
||||
std::string char_data_;
|
||||
time_t last_time_;
|
||||
std::string last_date_;
|
||||
};
|
||||
|
||||
static bool ConvertGpxTrkPtsToKml(const char* gpx_pathname,
|
||||
const char* kml_pathname) {
|
||||
kmldom::KmlFactory* kml_factory = kmldom::KmlFactory::GetFactory();
|
||||
// Create a <Document> to hand to the GPX parser.
|
||||
kmldom::DocumentPtr document = kml_factory->CreateDocument();
|
||||
// Make the <Document> a radio folder.
|
||||
const char* kRadioFolderId = "radio-folder-style";
|
||||
document->add_styleselector(CreateRadioFolder(kRadioFolderId));
|
||||
// <Document> has no inline style of its own so point its styleUrl to the
|
||||
// shared style.
|
||||
document->set_styleurl(std::string("#") + kRadioFolderId);
|
||||
// Add a shared style for all the Placemark's to use.
|
||||
const char* kStyleMapId = "style-map";
|
||||
document->add_styleselector(CreateStyleMap(kStyleMapId));
|
||||
|
||||
// Create the GPX parser directing its output to the <Document>.
|
||||
TrkPtHandler trk_pt_handler(document, kStyleMapId);
|
||||
|
||||
// Read the GPX file contents.
|
||||
std::string gpx_data;
|
||||
if (!kmlbase::File::ReadFileToString(gpx_pathname, &gpx_data)) {
|
||||
std::cerr << "read failed: " << gpx_pathname << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse the GPX data into the <Document>.
|
||||
std::string errors;
|
||||
|
||||
if (!ExpatParser::ParseString(gpx_data, &trk_pt_handler, &errors, false)) {
|
||||
std::cerr << "parse failed: " << gpx_pathname << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Put the <Document> in a <kml> element and write everything out to the
|
||||
// supplied pathname.
|
||||
kmldom::KmlPtr kml = kml_factory->CreateKml();
|
||||
kml->set_feature(document);
|
||||
std::string kml_data = kmldom::SerializePretty(kml);
|
||||
|
||||
if (!kmlbase::File::WriteStringToFile(kml_data, kml_pathname)) {
|
||||
std::cerr << "write failed: " << kml_pathname << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "usage: " << argv[0] << " input.gpx output.kml" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return ConvertGpxTrkPtsToKml(argv[1], argv[2]) ? 0 : 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
build_example(
|
||||
NAME gpxfly
|
||||
DEPENDS kmlconvenience)
|
||||
|
||||
build_example(
|
||||
NAME featuretour
|
||||
DEPENDS kmlconvenience)
|
||||
|
||||
|
||||
if(INSTALL_EXAMPLES)
|
||||
file(GLOB eg_files "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
|
||||
install(
|
||||
FILES ${eg_files}
|
||||
DESTINATION examples/gx)
|
||||
endif()
|
|
@ -0,0 +1,150 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This sample program generates a gx:Tour of all visible features in the given
|
||||
// KML or KMZ file. You supply two times (in seconds): a flyto_duration, used
|
||||
// as the time taken to fly between features, and a wait_duration, used as the
|
||||
// time spent dwelling at a feature before flying to the next.
|
||||
// Example usage: ./featuretour /my/cool/file.kml 10.0 5.0 tour.kml
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
using kmlconvenience::CreateFlyToForFeature;
|
||||
using kmlconvenience::CreateWait;
|
||||
using kmldom::FeaturePtr;
|
||||
using kmldom::GxFlyToPtr;
|
||||
using kmldom::GxPlaylistPtr;
|
||||
using kmldom::GxTourPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::KmlPtr;
|
||||
using kmlengine::GetRootFeature;
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
using kmlengine::VisitFeatureHierarchy;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
// This subclass of FeatureVisitor takes each Feature in the KmlFile and
|
||||
// attempts to generate a <gx:FlyTo> for that feature's view, appending it
|
||||
// to a supplied gx:Playlist. The GxPlaylistPtr must be non-NULL.
|
||||
class TourComposer : public kmlengine::FeatureVisitor {
|
||||
public:
|
||||
TourComposer(GxPlaylistPtr playlist, double flyto_duration,
|
||||
double dwell_duration)
|
||||
: playlist_(playlist), flyto_duration_(flyto_duration),
|
||||
dwell_duration_(dwell_duration) {
|
||||
}
|
||||
|
||||
virtual ~TourComposer() {}
|
||||
|
||||
// The callback from VisitFeatureHierarchy.
|
||||
virtual void VisitFeature(const FeaturePtr& feature) {
|
||||
if (!feature->get_visibility()) {
|
||||
return; // Skip if not visible.
|
||||
}
|
||||
// CreateFlyToForFeature may return NULL.
|
||||
GxFlyToPtr flyto = CreateFlyToForFeature(feature, flyto_duration_);
|
||||
if (!flyto) {
|
||||
return;
|
||||
}
|
||||
playlist_->add_gx_tourprimitive(flyto);
|
||||
playlist_->add_gx_tourprimitive(CreateWait(dwell_duration_));
|
||||
}
|
||||
|
||||
private:
|
||||
GxPlaylistPtr playlist_;
|
||||
double flyto_duration_;
|
||||
double dwell_duration_;
|
||||
};
|
||||
|
||||
static GxTourPtr GenerateTour(const KmlFilePtr& kml_file,
|
||||
double flyto_duration, double dwell_duration) {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
GxTourPtr tour = factory->CreateGxTour();
|
||||
tour->set_name("Play me!");
|
||||
GxPlaylistPtr playlist = factory->CreateGxPlaylist();
|
||||
TourComposer tour_composer(playlist, flyto_duration, dwell_duration);
|
||||
// Both VisitFeatureHierarchy and GetRootFeature are well-behaved with
|
||||
// respect to NULL returns.
|
||||
VisitFeatureHierarchy(GetRootFeature(kml_file->get_root()),
|
||||
tour_composer);
|
||||
tour->set_gx_playlist(playlist);
|
||||
return tour;
|
||||
}
|
||||
|
||||
static bool WriteTour(const GxTourPtr& tour, const char* outfile) {
|
||||
KmlPtr kml = KmlFactory::GetFactory()->CreateKml();
|
||||
kml->set_feature(tour);
|
||||
KmlFilePtr kmlfile = KmlFile::CreateFromImport(kml);
|
||||
if (!kmlfile) {
|
||||
cerr << "Error: could not create KmlFile from tour" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string kml_data;
|
||||
kmlfile->SerializeToString(&kml_data);
|
||||
if (!kmlbase::File::WriteStringToFile(kml_data, outfile)) {
|
||||
cerr << "write failed: " << outfile << endl;
|
||||
return false;
|
||||
}
|
||||
cout << "wrote " << outfile << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 5) {
|
||||
cerr << "usage: " << argv[0] <<
|
||||
" input.kml flyto_duration wait_duration output.kml" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string kml_data;
|
||||
if (!kmlbase::File::ReadFileToString(argv[1], &kml_data)) {
|
||||
cerr << "error: read of " << argv[1] << " failed" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string errors;
|
||||
KmlFilePtr kml_file = KmlFile::CreateFromParse(kml_data, &errors);
|
||||
if (!kml_file) {
|
||||
cerr << "parse failed: " << errors << endl;;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const double flyto_duration = strtod(argv[2], NULL);
|
||||
const double dwell_duration = strtod(argv[3], NULL);
|
||||
GxTourPtr tour = GenerateTour(kml_file, flyto_duration, dwell_duration);
|
||||
if (!tour) {
|
||||
cerr << "Could not create tour from " << argv[1] << endl;;
|
||||
return 1;
|
||||
}
|
||||
return WriteTour(tour, argv[4]) ? 0 : 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,222 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program converts a GPX file to a KML Tour of FlyTo's. Each <trkpt>
|
||||
// is translated to a <gx:FlyTo>/<LookAt> to the lat/lon of the trkpt and
|
||||
// all <gx:FlyTo>'s are put in one <gx:Tour>/<gx:Playlist>.
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/base/expat_parser.h"
|
||||
#include "kml/base/date_time.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/base/math_util.h"
|
||||
#include "kml/base/vec3.h"
|
||||
#include "kml/base/xml_namespaces.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/gpx_trk_pt_handler.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
|
||||
using kmlbase::AzimuthBetweenPoints;
|
||||
using kmlbase::DateTime;
|
||||
using kmlbase::DistanceBetweenPoints;
|
||||
using kmlbase::ExpatParser;
|
||||
using kmlbase::GroundDistanceFromRangeAndElevation;
|
||||
using kmlbase::HeightFromRangeAndElevation;
|
||||
using kmlbase::Vec3;
|
||||
using kmlconvenience::CreateAnimatedUpdateChangePoint;
|
||||
using kmlconvenience::CreatePointLatLon;
|
||||
using kmldom::CameraPtr;
|
||||
using kmldom::ChangePtr;
|
||||
using kmldom::ContainerPtr;
|
||||
using kmldom::DocumentPtr;
|
||||
using kmldom::GxAnimatedUpdatePtr;
|
||||
using kmldom::GxFlyToPtr;
|
||||
using kmldom::GxPlaylistPtr;
|
||||
using kmldom::GxTourPtr;
|
||||
using kmldom::GxWaitPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmldom::UpdatePtr;
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
|
||||
static const double kThreshold = 60.0; // seconds
|
||||
|
||||
// Return a <gx:FlyTo> with <Camera> as specified by the lat, lon and heading
|
||||
// and with a range scaled by speed. The duration is used as the <gx:duration>
|
||||
// of the <gx:FlyTo>.
|
||||
static GxFlyToPtr CreateGxFlyTo(double lat, double lon, double heading,
|
||||
double duration, double speed) {
|
||||
KmlFactory* kml_factory = KmlFactory::GetFactory();
|
||||
|
||||
// Tilt the camera back as speed increases, but clamp max tilt.
|
||||
double tilt = 0 + speed * 4;
|
||||
if (tilt > 65.) tilt = 65.;
|
||||
|
||||
// The distance along the vector from the gpx point to eyepoint.
|
||||
double range = 100.0 + tilt * 7;
|
||||
|
||||
// The ground distance between the gpx point and the subpoint of where
|
||||
// we'll place the camera.
|
||||
double distance = GroundDistanceFromRangeAndElevation(range, 90 - tilt);
|
||||
|
||||
// The lat,lon of the camera.
|
||||
double reverse_heading = fmod(heading + 180.0, 360.0);
|
||||
Vec3 camera_position =
|
||||
kmlbase::LatLngOnRadialFromPoint(lat, lon, distance, reverse_heading);
|
||||
|
||||
CameraPtr camera = kml_factory->CreateCamera();
|
||||
camera->set_latitude(camera_position.get_latitude());
|
||||
camera->set_longitude(camera_position.get_longitude());
|
||||
camera->set_altitude(HeightFromRangeAndElevation(range, 90 - tilt));
|
||||
camera->set_heading(heading);
|
||||
// Nudge the tilt up a little to move the icon towards the bottom of the
|
||||
// screen.
|
||||
camera->set_tilt(tilt *= 1.1);
|
||||
GxFlyToPtr flyto = kml_factory->CreateGxFlyTo();
|
||||
flyto->set_abstractview(camera);
|
||||
flyto->set_gx_duration(duration);
|
||||
// TODO: the first FlyTo in a Playlist often better as bounce
|
||||
flyto->set_gx_flytomode(kmldom::GX_FLYTOMODE_SMOOTH);
|
||||
return flyto;
|
||||
}
|
||||
|
||||
// This specialization of the GpxTrkPtHandler converts each GPX <trkpt> to
|
||||
// a KML <gx:AnimatedUpdate> + <gx:FlyTo>.
|
||||
class TourTrkPtHandler : public kmlconvenience::GpxTrkPtHandler {
|
||||
public:
|
||||
TourTrkPtHandler(ContainerPtr container)
|
||||
: placemark_id_("moving-placemark"),
|
||||
previous_when_(0),
|
||||
container_(container) {
|
||||
}
|
||||
|
||||
void NewTour() {
|
||||
GxTourPtr tour(KmlFactory::GetFactory()->CreateGxTour());
|
||||
tour->set_name("Play me!");
|
||||
playlist_ = KmlFactory::GetFactory()->CreateGxPlaylist();
|
||||
tour->set_gx_playlist(playlist_);
|
||||
container_->add_feature(tour);
|
||||
}
|
||||
|
||||
// This is called for each <trkpt>.
|
||||
virtual void HandlePoint(const kmlbase::Vec3& where,
|
||||
const std::string& when) {
|
||||
time_t when_timet = DateTime::ToTimeT(when);
|
||||
if (when_timet == 0) {
|
||||
std::cerr << "Ignoring point with no time" << std::endl;
|
||||
return;
|
||||
}
|
||||
if (previous_when_ == 0) { // First point
|
||||
PlacemarkPtr placemark = KmlFactory::GetFactory()->CreatePlacemark();
|
||||
placemark->set_id(placemark_id_);
|
||||
placemark->set_geometry(CreatePointLatLon(where.get_latitude(),
|
||||
where.get_longitude()));
|
||||
container_->add_feature(placemark);
|
||||
NewTour();
|
||||
} else {
|
||||
// Convert the GPX <trkpt> to a <gx:AnimatedUpdate> + <gx:FlyTo>.
|
||||
// Note, it's quite important that the AnimatedUpdate appear _before_
|
||||
// the FlyTo given that a FlyTo will happen during an AnimatedUpdate
|
||||
// but an AnimatedUpdate will _not_ start until a FlyTo is done.
|
||||
const double duration = when_timet - previous_when_;
|
||||
if (duration < 0) {
|
||||
std::cerr << "Ignoring point out of time order." << std::endl;
|
||||
} else if (duration > kThreshold) {
|
||||
NewTour();
|
||||
} else {
|
||||
playlist_->add_gx_tourprimitive(
|
||||
CreateAnimatedUpdateChangePoint(placemark_id_, where, duration));
|
||||
const double heading = AzimuthBetweenPoints(
|
||||
previous_where_.get_latitude(), previous_where_.get_longitude(),
|
||||
where.get_latitude(), where.get_longitude());
|
||||
const double speed = DistanceBetweenPoints(
|
||||
previous_where_.get_latitude(), previous_where_.get_longitude(),
|
||||
where.get_latitude(), where.get_longitude()) / duration;
|
||||
playlist_->add_gx_tourprimitive(
|
||||
CreateGxFlyTo(where.get_latitude(), where.get_longitude(),
|
||||
heading, duration, speed));
|
||||
// Wait 0 to create smooth animated update...
|
||||
playlist_->add_gx_tourprimitive(kmlconvenience::CreateWait(0));
|
||||
}
|
||||
}
|
||||
previous_when_ = when_timet;
|
||||
previous_where_ = where;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string placemark_id_;
|
||||
kmlbase::Vec3 previous_where_;
|
||||
time_t previous_when_;
|
||||
ContainerPtr container_;
|
||||
GxPlaylistPtr playlist_;
|
||||
};
|
||||
|
||||
// Parse the gpx file and make a KML tour to save out to the kml file.
|
||||
static bool CreateGpxTour(const char* gpx_pathname, const char* kml_pathname) {
|
||||
KmlFactory* kml_factory = KmlFactory::GetFactory();
|
||||
// Create a <Document> and hand it to the GPX parser.
|
||||
DocumentPtr document = kml_factory->CreateDocument();
|
||||
document->set_open(1);
|
||||
TourTrkPtHandler tour_maker(document);
|
||||
|
||||
// Read the GPX file contents.
|
||||
std::string gpx_data;
|
||||
if (!kmlbase::File::ReadFileToString(gpx_pathname, &gpx_data)) {
|
||||
std::cerr << "read failed: " << gpx_pathname << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse the GPX data writing a Tour into the <Document>.
|
||||
std::string errors;
|
||||
if (!ExpatParser::ParseString(gpx_data, &tour_maker, &errors, false)) {
|
||||
std::cerr << "parse failed: " << gpx_pathname << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Put the <Document> in a <kml> element and write everything out to the
|
||||
// supplied pathname.
|
||||
KmlPtr kml = kml_factory->CreateKml();
|
||||
kml->set_feature(document);
|
||||
KmlFilePtr kml_file = KmlFile::CreateFromImport(kml);
|
||||
std::string kml_data;
|
||||
kml_file->SerializeToString(&kml_data);
|
||||
|
||||
if (!kmlbase::File::WriteStringToFile(kml_data, kml_pathname)) {
|
||||
std::cerr << "write failed: " << kml_pathname << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "usage: " << argv[0] << " input.gpx output.kml" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return CreateGpxTour(argv[1], argv[2]) ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
|
||||
add_library(curlfetch curlfetch.cc)
|
||||
target_link_libraries(curlfetch ${CURL_LIBRARIES})
|
||||
|
||||
build_example(
|
||||
NAME csvurl2gmap
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME getgmapkml
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME getgsheetcsv
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME getgsheetkml
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME gsheet2gmap
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME kmlwalk
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME kmzfetch
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME listfeed
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME listgdocs
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME listgmaps
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME listgphotos
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME resolvestyle
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME searchgmap
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME uploadgmap
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME uploadgmapcsv
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME uploadgmapkml
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME uploadgsheet
|
||||
DEPENDS kmlconvenience curlfetch)
|
||||
|
||||
build_example(
|
||||
NAME xsdprint
|
||||
DEPENDS kmlconvenience kmlxsd curlfetch)
|
||||
|
||||
if(INSTALL_EXAMPLES)
|
||||
file(GLOB eg_files "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
|
||||
install(
|
||||
FILES ${eg_files}
|
||||
DESTINATION examples/hellonet)
|
||||
|
||||
install(
|
||||
FILES README curlfetch.h prompt.h
|
||||
DESTINATION examples/hellonet)
|
||||
endif()
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
These assume CURL 7.17.1 built and installed with all defaults:
|
||||
|
||||
/usr/local/include/curl/curl.h
|
||||
/usr/local/lib/libcurl*
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
// Copyright 2010, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <termios.h>
|
||||
#include <time.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/convenience/atom_util.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/google_maps_data.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
|
||||
using kmlconvenience::GoogleMapsData;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
std::cout << "usage: " << argv[0] << " url.csv" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
const char* csv_url = argv[1];
|
||||
const char* title = argv[1]; // xx last component
|
||||
|
||||
std::string csv_data;
|
||||
if (!CurlToString(csv_url, &csv_data)) {
|
||||
std::cerr << "Curl fetch failed: " << csv_url << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Fetched " << csv_data.size() << " bytes." << std::endl;
|
||||
|
||||
std::string user;
|
||||
std::string password;
|
||||
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
CurlHttpClient* curl_http_client =
|
||||
new CurlHttpClient("libkml:examples:hellonet:csvurl2gmap");
|
||||
if (!curl_http_client->Login(GoogleMapsData::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::scoped_ptr<GoogleMapsData> google_maps_data(
|
||||
GoogleMapsData::Create(curl_http_client));
|
||||
|
||||
string errors;
|
||||
kmldom::AtomEntryPtr map_entry = google_maps_data->PostCsv(title, csv_data,
|
||||
&errors);
|
||||
// If the PostCsv fails it may be due to CSV errors.
|
||||
if (!map_entry.get()) {
|
||||
std::cerr << "PostCsv failed:" << std::endl;
|
||||
std::cerr << errors << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// PostCsv succeeded: print the id of the new map.
|
||||
std::string map_feed_uri;
|
||||
kmlconvenience::AtomUtil::FindRelUrl(*map_entry, "self", &map_feed_uri);
|
||||
std::cout << "Upload succeeded. Map feed URI: " << map_feed_uri
|
||||
<< std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "curlfetch.h"
|
||||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
// CURLOPT_WRITEFUNCTION:
|
||||
// size*nmemb bytes of data are at ptr, stream is user data
|
||||
// return must be size*nmemb or curl itself will fail.
|
||||
static size_t FetchToString(void* ptr, size_t size, size_t nmemb, void* user) {
|
||||
// static function, only user is DoCurlToString which uses CURLOPT_WRITEDATA
|
||||
// to set the "user" arg which is the C++ string (buffer) to write to.
|
||||
size_t nbytes = size * nmemb;
|
||||
string *output_buffer = reinterpret_cast<string*>(user);
|
||||
output_buffer->append(reinterpret_cast<char*>(ptr), nbytes);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
// Separate worker function to simplify bool return logic.
|
||||
static bool DoCurlToString(CURL* curl, const char* url, string* data) {
|
||||
#define CURLOK(f) (f == CURLE_OK)
|
||||
if (CURLOK(curl_easy_setopt(curl, CURLOPT_URL, url)) &&
|
||||
CURLOK(curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, FetchToString)) &&
|
||||
CURLOK(curl_easy_setopt(curl, CURLOPT_WRITEDATA,
|
||||
reinterpret_cast<void*>(data))) &&
|
||||
CURLOK(curl_easy_perform(curl))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wrapper to manage curl handle. Very simple stateless implementation. Less
|
||||
// simplistic would be to reuse the CURL* handle between invocations.
|
||||
// TODO: implement in terms of CurlHttpRequest and remove FetchToString() and
|
||||
// DoCurlToString() above (both static so nothing external knows they exist).
|
||||
bool CurlToString(const char* url, string* data) {
|
||||
CURL* curl = curl_easy_init();
|
||||
bool ret = DoCurlToString(curl, url, data);
|
||||
curl_easy_cleanup(curl);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool CurlHttpRequest(
|
||||
kmlconvenience::HttpMethodEnum http_method,
|
||||
const std::string& uri,
|
||||
const kmlconvenience::StringPairVector* request_headers,
|
||||
const std::string* data,
|
||||
std::string* response) {
|
||||
CURL* curl = curl_easy_init();
|
||||
curl_easy_setopt(curl, CURLOPT_URL, uri.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
||||
if (response) {
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, FetchToString);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, response);
|
||||
}
|
||||
if (uri.compare(0, 8, "https://") == 0) {
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
}
|
||||
if (data) {
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data->data());
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data->size());
|
||||
}
|
||||
struct curl_slist *curl_headers = NULL;
|
||||
if (request_headers) {
|
||||
for (unsigned int i = 0; i < request_headers->size(); ++i) {
|
||||
curl_headers =
|
||||
curl_slist_append(curl_headers,
|
||||
kmlconvenience::HttpClient::FormatHeader(
|
||||
(*request_headers)[i]).c_str());
|
||||
}
|
||||
}
|
||||
if (http_method == kmlconvenience::HTTP_POST) {
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||
} else if (http_method == kmlconvenience::HTTP_GET) {
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
|
||||
curl_headers = curl_slist_append(curl_headers,
|
||||
"Content-Type: application/atom+xml");
|
||||
}
|
||||
if (curl_headers) {
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers);
|
||||
}
|
||||
CURLcode curl_code = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
return curl_code == CURLE_OK;
|
||||
}
|
||||
|
||||
CurlHttpClient::CurlHttpClient(const std::string &application_name)
|
||||
: HttpClient(application_name) {
|
||||
}
|
||||
|
||||
bool CurlHttpClient::SendRequest(
|
||||
kmlconvenience::HttpMethodEnum http_method,
|
||||
const std::string& request_uri,
|
||||
const kmlconvenience::StringPairVector* request_headers,
|
||||
const std::string* data,
|
||||
std::string* response) const {
|
||||
kmlconvenience::StringPairVector headers;
|
||||
kmlconvenience::HttpClient::AppendHeaders(get_headers(), &headers);
|
||||
if (request_headers) {
|
||||
kmlconvenience::HttpClient::AppendHeaders(*request_headers, &headers);
|
||||
}
|
||||
return CurlHttpRequest(http_method, request_uri, &headers, data, response);
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef EXAMPLES_HELLONET_CURLFETCH_H__
|
||||
#define EXAMPLES_HELLONET_CURLFETCH_H__
|
||||
|
||||
#include <string>
|
||||
#include "kml/base/net_cache.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
|
||||
bool CurlToString(const char* url, std::string* data);
|
||||
|
||||
// This class matches the NetFetcher concept used with kmlbase::NetCache.
|
||||
class CurlNetFetcher : public kmlbase::NetFetcher {
|
||||
public:
|
||||
bool FetchUrl(const std::string& url, std::string* data) const {
|
||||
return CurlToString(url.c_str(), data);
|
||||
}
|
||||
};
|
||||
|
||||
// This HttpClient uses libcurl to send the request.
|
||||
class CurlHttpClient : public kmlconvenience::HttpClient {
|
||||
public:
|
||||
CurlHttpClient(const std::string& application_name);
|
||||
|
||||
// HttpClient::SendRequest()
|
||||
virtual bool SendRequest(
|
||||
kmlconvenience::HttpMethodEnum http_method,
|
||||
const std::string& request_uri,
|
||||
const kmlconvenience::StringPairVector* request_headers,
|
||||
const std::string* post_data,
|
||||
std::string* response) const;
|
||||
};
|
||||
|
||||
#endif // EXAMPLES_HELLONET_CURLFETCH_H__
|
|
@ -0,0 +1,143 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This returns the KML of the specific Google My Maps.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/convenience/atom_util.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
#include "kml/convenience/google_maps_data.h"
|
||||
|
||||
using kmlconvenience::GoogleMapsData;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string map_title;
|
||||
std::string output;
|
||||
|
||||
// Get the user logged in first.
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
CurlHttpClient* curl_http_client = new CurlHttpClient(
|
||||
"libkml:examples:hellonet:getmapkml");
|
||||
if (!curl_http_client->Login(GoogleMapsData::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Login succeeded..." << std::endl;
|
||||
|
||||
// Create a GoogleMapsData client from the logged in HttpClient and
|
||||
// get the user's list of maps.
|
||||
boost::scoped_ptr<GoogleMapsData> google_maps_data(
|
||||
GoogleMapsData::Create(curl_http_client));
|
||||
|
||||
again:
|
||||
kmldom::AtomFeedPtr meta_feed = google_maps_data->GetMetaFeed();
|
||||
if (!meta_feed.get()) {
|
||||
std::cerr << "GetMetaFeed failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "You have " << meta_feed->get_entry_array_size() << " maps."
|
||||
<< std::endl;
|
||||
|
||||
// For each <entry> in the <feed>...
|
||||
for (size_t e = 0; e < meta_feed->get_entry_array_size(); ++e) {
|
||||
const kmldom::AtomEntryPtr& entry = meta_feed->get_entry_array_at(e);
|
||||
// Print the <title>:
|
||||
std::cout << "[title] " << entry->get_title() << std::endl;
|
||||
std::string feature_feed_uri;
|
||||
if (GoogleMapsData::GetFeatureFeedUri(entry, &feature_feed_uri)) {
|
||||
std::cout << " [feature feed] " << feature_feed_uri << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Map title: ";
|
||||
// Use std::getline here to capture the entire line.
|
||||
std::getline(std::cin, map_title);
|
||||
|
||||
const kmldom::AtomEntryPtr& map_entry =
|
||||
kmlconvenience::AtomUtil::FindEntryByTitle(meta_feed, map_title);
|
||||
|
||||
if (!map_entry.get()) {
|
||||
std::cout << "No map with title: " << map_title << std::endl;
|
||||
if (Prompt::PromptAgain("Try another title? ")) {
|
||||
goto again;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string feature_feed_uri;
|
||||
if (!GoogleMapsData::GetFeatureFeedUri(map_entry, &feature_feed_uri)) {
|
||||
std::cout << "No Feature Feed for this map?" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// A map with this title was found. Go fetch
|
||||
std::cout << "Feature Feed URI: " << feature_feed_uri << std::endl;
|
||||
const kmldom::AtomFeedPtr feature_feed =
|
||||
google_maps_data->GetFeatureFeedByUri(feature_feed_uri);
|
||||
|
||||
std::cout << "There are " << feature_feed->get_entry_array_size()
|
||||
<< " entries in this map." << std::endl;
|
||||
|
||||
std::cout << "Output file: ";
|
||||
std::cin >> output;
|
||||
|
||||
// Dig out the KML features in the feed and put them in a <Document>.
|
||||
kmldom::KmlPtr kml = kmldom::KmlFactory::GetFactory()->CreateKml();
|
||||
kmldom::ContainerPtr container =
|
||||
google_maps_data->CreateDocumentOfMapFeatures(feature_feed);
|
||||
kml->set_feature(container);
|
||||
|
||||
std::cout << "There are " << container->get_feature_array_size()
|
||||
<< " Features in the map saved to " << output << "." << std::endl;
|
||||
|
||||
// Use KmlFile's serialize to get xml proper header and xmlns.
|
||||
boost::scoped_ptr<kmlengine::KmlFile> kml_file(
|
||||
kmlengine::KmlFile::CreateFromImport(kml));
|
||||
std::string xml;
|
||||
kml_file->SerializeToString(&xml);
|
||||
kmlbase::File::WriteStringToFile(xml, output.c_str());
|
||||
|
||||
std::cin.get();
|
||||
if (Prompt::PromptAgain("Get KML for another map? ")) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This downloads the specified Google Spreadsheet as a CSV file.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/convenience/atom_util.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
#include "kml/convenience/google_doc_list.h"
|
||||
#include "kml/convenience/google_spreadsheets.h"
|
||||
|
||||
using kmlconvenience::AtomUtil;
|
||||
using kmlconvenience::GoogleDocList;
|
||||
using kmlconvenience::GoogleSpreadsheets;
|
||||
using kmldom::AtomEntryPtr;
|
||||
using kmldom::AtomFeedPtr;
|
||||
using kmldom::AsAtomEntry;
|
||||
using kmldom::AsAtomFeed;
|
||||
using kmldom::ParseAtom;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string spreadsheet_title;
|
||||
std::string output;
|
||||
|
||||
// Get the user logged in first.
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
// Since GoogleSpreadsheets doesn't (yet?) provide a resource id we get that
|
||||
// from GoogleDocList.
|
||||
CurlHttpClient* doc_list_http_client = new CurlHttpClient(
|
||||
"libkml:examples:hellonet:getgsheetcsv");
|
||||
if (!doc_list_http_client->Login(GoogleDocList::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
boost::scoped_ptr<GoogleDocList> google_doc_list(
|
||||
GoogleDocList::Create(doc_list_http_client));
|
||||
|
||||
// Login also to GoogleSpreadsheets for the actual CSV fetch.
|
||||
CurlHttpClient* spreadsheets_http_client = new CurlHttpClient(
|
||||
"libkml:examples:hellonet:getgsheetcsv");
|
||||
if (!spreadsheets_http_client->Login(GoogleSpreadsheets::get_service_name(),
|
||||
user, password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
boost::scoped_ptr<GoogleSpreadsheets> google_spreadsheets(
|
||||
GoogleSpreadsheets::Create(spreadsheets_http_client));
|
||||
|
||||
std::cout << "Login succeeded..." << std::endl;
|
||||
|
||||
kmldom::AtomFeedPtr meta_feed = google_doc_list->GetMetaFeed();
|
||||
if (!meta_feed.get()) {
|
||||
std::cerr << "GetMetaFeed failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
again:
|
||||
std::cout << "You have " << meta_feed->get_entry_array_size()
|
||||
<< " docs:" << std::endl;
|
||||
|
||||
for (size_t l = 0; l < meta_feed->get_entry_array_size(); ++l) {
|
||||
const kmldom::AtomEntryPtr& entry = meta_feed->get_entry_array_at(l);
|
||||
kmldom::AtomCategoryPtr category = AtomUtil::FindCategoryByScheme(*entry,
|
||||
"kind");
|
||||
std::string kind = (category && category->has_label())
|
||||
? category->get_label() : "[unknown kind]";
|
||||
std::cout << kind << ": " << entry->get_title() << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Spreadsheet title: ";
|
||||
// Use std::getline here to capture the entire line.
|
||||
std::getline(std::cin, spreadsheet_title);
|
||||
|
||||
const kmldom::AtomEntryPtr& spreadsheet_entry =
|
||||
kmlconvenience::AtomUtil::FindEntryByTitle(meta_feed, spreadsheet_title);
|
||||
|
||||
if (!spreadsheet_entry.get()) {
|
||||
std::cout << "No spreadsheet with title: " << spreadsheet_title
|
||||
<< std::endl;
|
||||
if (Prompt::PromptAgain("Try another title? ")) {
|
||||
goto again;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
string spreadsheet_data;
|
||||
if (!google_spreadsheets->DownloadSpreadsheet(spreadsheet_entry, "csv",
|
||||
&spreadsheet_data)) {
|
||||
std::cout << "Download failed: " << spreadsheet_title
|
||||
<< std::endl;
|
||||
if (Prompt::PromptAgain("Try another title? ")) {
|
||||
goto again;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Output file: ";
|
||||
std::cin >> output;
|
||||
|
||||
kmlbase::File::WriteStringToFile(spreadsheet_data, output.c_str());
|
||||
|
||||
std::cin.get();
|
||||
if (Prompt::PromptAgain("Get CSV for another spreadsheet? ")) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This creates KML from a suitable Google spreadsheet. This looks exactly
|
||||
// only for the "name", "latitude", and "longitude" rows and creates a
|
||||
// <Point> <Placemark> for each one.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/convenience/atom_util.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
#include "kml/convenience/google_spreadsheets.h"
|
||||
|
||||
using kmlconvenience::AtomUtil;
|
||||
using kmldom::AtomEntryPtr;
|
||||
using kmldom::AtomFeedPtr;
|
||||
using kmldom::AsAtomEntry;
|
||||
using kmldom::AsAtomFeed;
|
||||
using kmldom::ParseAtom;
|
||||
|
||||
// Parse a string of this form: <namempace|key>val</namespace|key>.
|
||||
static bool ParseGsxElement(const std::string& element, std::string* key,
|
||||
std::string* val) {
|
||||
size_t pipe = element.find('|');
|
||||
if (pipe == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
size_t gt = element.find('>', pipe + 1);
|
||||
if (gt == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
size_t lt = element.find('<', gt + 1);
|
||||
if (lt == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
*key = element.substr(pipe + 1, gt - pipe - 1);
|
||||
*val = element.substr(gt + 1, lt - gt - 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Each Google Spreadsheets listfeed <entry> holds a spreadsheet row in a
|
||||
// <gsx:COLUMN> element for each cell.
|
||||
// For example:
|
||||
// If the spreadsheet is...
|
||||
// 0 | name | longitude | latitude |
|
||||
// 1 | croc hotel | 132.831455817379 | -12.6704922515546 |
|
||||
// ...then this appears in the entry for the 1th row:
|
||||
// <entry>
|
||||
// <gsx:name>croc hotel</gsx:name>
|
||||
// <gsx:longitude>132.831455817379</gsx:longitude>
|
||||
// <gsx:latitude>-12.6704922515546</gsx:latitude>
|
||||
// <entry>
|
||||
// See: http://code.google.com/apis/spreadsheets/data/3.0/developers_guide_protocol.html#ListFeeds
|
||||
// TODO: create a more general form suitable for inclusion in the library itself
|
||||
kmldom::PlacemarkPtr CreatePlacemarkFromEntry(
|
||||
const kmldom::AtomEntryPtr& entry) {
|
||||
std::string name;
|
||||
std::string longitude;
|
||||
std::string latitude;
|
||||
kmldom::ExtendedDataPtr extended_data =
|
||||
kmldom::KmlFactory::GetFactory()->CreateExtendedData();
|
||||
size_t usize = entry->get_unknown_elements_array_size();
|
||||
for (size_t u = 0; u < usize; ++u) {
|
||||
const std::string& us = entry->get_unknown_elements_array_at(u);
|
||||
std::string key;
|
||||
std::string val;
|
||||
if (ParseGsxElement(us, &key, &val)) {
|
||||
if (key == "name") {
|
||||
name = val;
|
||||
} else if (key == "longitude") {
|
||||
longitude = val;
|
||||
} else if (key == "latitude") {
|
||||
latitude = val;
|
||||
} else {
|
||||
extended_data->add_data(kmlconvenience::CreateDataNameValue(key, val));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!name.empty() && !longitude.empty() && !latitude.empty()) {
|
||||
kmldom::PlacemarkPtr placemark = kmlconvenience::CreatePointPlacemark(
|
||||
name, strtod(latitude.c_str(), NULL), strtod(longitude.c_str(), NULL));
|
||||
if (extended_data->get_data_array_size() > 0) {
|
||||
placemark->set_extendeddata(extended_data);
|
||||
}
|
||||
// TODO: set <atom:link> back to this spreadsheet cell.
|
||||
return placemark;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static AtomFeedPtr GetContentSrcFeed(CurlHttpClient* curl_http_client,
|
||||
const AtomEntryPtr& entry) {
|
||||
// worksheet feed = <content src="..."/> of meta feed entry
|
||||
std::string content_src_uri;
|
||||
if (AtomUtil::GetContentSrc(entry, &content_src_uri)) {
|
||||
std::string content_src_xml;
|
||||
if (curl_http_client->SendRequest(kmlconvenience::HTTP_GET,
|
||||
content_src_uri, NULL, NULL,
|
||||
&content_src_xml)) {
|
||||
return AsAtomFeed(ParseAtom(content_src_xml, NULL));
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string spreadsheet_title;
|
||||
std::string output;
|
||||
|
||||
// Get the user logged in first.
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
CurlHttpClient* curl_http_client = new CurlHttpClient(
|
||||
"libkml:examples:hellonet:getgsheetkml");
|
||||
if (!curl_http_client->Login("wise", user, password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Login succeeded..." << std::endl;
|
||||
|
||||
// Create a GoogleMapsData client from the logged in HttpClient and
|
||||
// get the user's list of spreadsheets.
|
||||
boost::scoped_ptr<kmlconvenience::GoogleSpreadsheets> google_spreadsheets(
|
||||
kmlconvenience::GoogleSpreadsheets::Create(curl_http_client));
|
||||
kmldom::AtomFeedPtr meta_feed = google_spreadsheets->GetMetaFeed();
|
||||
if (!meta_feed.get()) {
|
||||
std::cerr << "GetMetaFeed failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "You have " << meta_feed->get_entry_array_size()
|
||||
<< " spreadsheets:" << std::endl;
|
||||
|
||||
for (size_t l = 0; l < meta_feed->get_entry_array_size(); ++l) {
|
||||
const kmldom::AtomEntryPtr& entry = meta_feed->get_entry_array_at(l);
|
||||
std::cout << entry->get_title() << std::endl;
|
||||
}
|
||||
|
||||
again:
|
||||
std::cout << "Spreadsheet title: ";
|
||||
// Use std::getline here to capture the entire line.
|
||||
std::getline(std::cin, spreadsheet_title);
|
||||
|
||||
const kmldom::AtomEntryPtr& spreadsheet_entry =
|
||||
kmlconvenience::AtomUtil::FindEntryByTitle(meta_feed, spreadsheet_title);
|
||||
|
||||
if (!spreadsheet_entry.get()) {
|
||||
std::cout << "No spreadsheet with title: " << spreadsheet_title
|
||||
<< std::endl;
|
||||
if (Prompt::PromptAgain("Try another title? ")) {
|
||||
goto again;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
const kmldom::AtomFeedPtr worksheet_feed =
|
||||
GetContentSrcFeed(curl_http_client, spreadsheet_entry);
|
||||
if (!worksheet_feed.get() || worksheet_feed->get_entry_array_size() < 1) {
|
||||
std::cerr << "Worksheet feed has no entry?" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// The 0th <entry>'s <content src="..."/> in the worksheet <feed> points to
|
||||
// the list feed.
|
||||
const kmldom::AtomFeedPtr list_feed =
|
||||
GetContentSrcFeed(curl_http_client,
|
||||
worksheet_feed->get_entry_array_at(0));
|
||||
if (!list_feed.get() || list_feed->get_entry_array_size() < 1) {
|
||||
std::cerr << "No list feed?" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "This spreadsheet has " << list_feed->get_entry_array_size()
|
||||
<< " rows." << std::endl;
|
||||
|
||||
kmldom::KmlFactory* kml_factory = kmldom::KmlFactory::GetFactory();
|
||||
kmldom::DocumentPtr document = kml_factory->CreateDocument();
|
||||
// TODO: set <atom:link> back to this spreadsheet.
|
||||
|
||||
for (size_t l = 0; l < list_feed->get_entry_array_size(); ++l) {
|
||||
document->add_feature(CreatePlacemarkFromEntry(
|
||||
list_feed->get_entry_array_at(l)));
|
||||
}
|
||||
|
||||
kmldom::KmlPtr kml = kml_factory->CreateKml();
|
||||
kml->set_feature(document);
|
||||
|
||||
std::cout << "Output file: ";
|
||||
std::cin >> output;
|
||||
|
||||
std::cout << "There are " << document->get_feature_array_size()
|
||||
<< " Features in the KML saved to " << output << "." << std::endl;
|
||||
|
||||
// Use KmlFile's serialize to get xml proper header and xmlns.
|
||||
boost::scoped_ptr<kmlengine::KmlFile> kml_file(
|
||||
kmlengine::KmlFile::CreateFromImport(kml));
|
||||
std::string xml;
|
||||
kml_file->SerializeToString(&xml);
|
||||
kmlbase::File::WriteStringToFile(xml, output.c_str());
|
||||
|
||||
std::cin.get();
|
||||
if (Prompt::PromptAgain("Create KML for another spreadsheet? ")) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,183 @@
|
|||
// Copyright 2010, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This creates a Google My Map from a Google Spreadsheet using CSV as the data
|
||||
// exchange. The first line of the spreadsheet must include a "latitude" and
|
||||
// "longitude". A "name" and "description" column is used for <name>
|
||||
// and <description>. Any other column heading is used as an
|
||||
// <ExtendedData>/<Data> item. NOTE: the My Maps UI does not show the
|
||||
// ExtendedData/Data fields, but these are used for Maps Data API attribute
|
||||
// search and are available in exported KML: to view in Google Earth.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/convenience/atom_util.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
#include "kml/convenience/google_doc_list.h"
|
||||
#include "kml/convenience/google_maps_data.h"
|
||||
#include "kml/convenience/google_spreadsheets.h"
|
||||
|
||||
using kmlconvenience::AtomUtil;
|
||||
using kmlconvenience::GoogleDocList;
|
||||
using kmlconvenience::GoogleMapsData;
|
||||
using kmlconvenience::GoogleSpreadsheets;
|
||||
using kmldom::AtomEntryPtr;
|
||||
using kmldom::AtomFeedPtr;
|
||||
using kmldom::AsAtomEntry;
|
||||
using kmldom::AsAtomFeed;
|
||||
using kmldom::ParseAtom;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string spreadsheet_title;
|
||||
std::string output;
|
||||
|
||||
// Get the user logged in first.
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
// Get an auth token for each Google Data service this program uses:
|
||||
// 1) Documents List, 2) Spreadsheets, 3) Maps Data.
|
||||
// Fail right away if we can't log into all of these.
|
||||
|
||||
// Since GoogleSpreadsheets doesn't (yet?) provide a resource id we get that
|
||||
// from GoogleDocList.
|
||||
CurlHttpClient* doc_list_http_client = new CurlHttpClient(
|
||||
"libkml:examples:hellonet::gsheet2gmap");
|
||||
if (!doc_list_http_client->Login(GoogleDocList::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login to Google Doc List failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
boost::scoped_ptr<GoogleDocList> google_doc_list(
|
||||
GoogleDocList::Create(doc_list_http_client));
|
||||
|
||||
// Login also to GoogleSpreadsheets for the actual CSV fetch.
|
||||
CurlHttpClient* spreadsheets_http_client = new CurlHttpClient(
|
||||
"libkml:examples:hellonet::gsheet2gmap");
|
||||
if (!spreadsheets_http_client->Login(GoogleSpreadsheets::get_service_name(),
|
||||
user, password)) {
|
||||
std::cerr << "Login to Google Spreadsheets failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
boost::scoped_ptr<GoogleSpreadsheets> google_spreadsheets(
|
||||
GoogleSpreadsheets::Create(spreadsheets_http_client));
|
||||
|
||||
// Finally also log in now to Google Maps Data.
|
||||
CurlHttpClient* maps_data_http_client = new CurlHttpClient(
|
||||
"libkml:examples:hellonet::gsheet2gmap");
|
||||
if (!maps_data_http_client->Login(GoogleMapsData::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login to Google Maps Data failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::scoped_ptr<GoogleMapsData> google_maps_data(
|
||||
GoogleMapsData::Create(maps_data_http_client));
|
||||
|
||||
std::cout << "Login succeeded..." << std::endl;
|
||||
|
||||
again:
|
||||
// Tell the user what docs they have.
|
||||
kmldom::AtomFeedPtr meta_feed = google_doc_list->GetMetaFeed();
|
||||
if (!meta_feed.get()) {
|
||||
std::cerr << "GetMetaFeed failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "You have " << meta_feed->get_entry_array_size()
|
||||
<< " docs:" << std::endl;
|
||||
|
||||
for (size_t l = 0; l < meta_feed->get_entry_array_size(); ++l) {
|
||||
const kmldom::AtomEntryPtr& entry = meta_feed->get_entry_array_at(l);
|
||||
kmldom::AtomCategoryPtr category = AtomUtil::FindCategoryByScheme(*entry,
|
||||
"kind");
|
||||
std::string kind = (category && category->has_label())
|
||||
? category->get_label() : "[unknown kind]";
|
||||
std::cout << kind << ": " << entry->get_title() << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Spreadsheet title: ";
|
||||
// Use std::getline here to capture the entire line.
|
||||
std::getline(std::cin, spreadsheet_title);
|
||||
|
||||
const kmldom::AtomEntryPtr& spreadsheet_entry =
|
||||
kmlconvenience::AtomUtil::FindEntryByTitle(meta_feed, spreadsheet_title);
|
||||
|
||||
if (!spreadsheet_entry.get()) {
|
||||
std::cout << "No spreadsheet with title: " << spreadsheet_title
|
||||
<< std::endl;
|
||||
if (Prompt::PromptAgain("Try another title? ")) {
|
||||
goto again;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get the spreadsheet in CSV form.
|
||||
string csv_data;
|
||||
if (!google_spreadsheets->DownloadSpreadsheet(spreadsheet_entry, "csv",
|
||||
&csv_data)) {
|
||||
std::cout << "Spreadsheets CSV download failed: " << spreadsheet_title
|
||||
<< std::endl;
|
||||
if (Prompt::PromptAgain("Try another title? ")) {
|
||||
goto again;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "CSV bytes: " << csv_data.size() << std::endl;
|
||||
|
||||
std::cout << "First line: " << csv_data.substr(0, csv_data.find('\n'))
|
||||
<< std::endl;
|
||||
|
||||
std::string errors;
|
||||
kmldom::AtomEntryPtr map_entry =
|
||||
google_maps_data->PostCsv(spreadsheet_title, csv_data, &errors);
|
||||
if (!map_entry) {
|
||||
std::cerr << "CSV POST failed:" << std::endl;
|
||||
std::cerr << errors << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string map_feed_uri;
|
||||
kmlconvenience::AtomUtil::FindRelUrl(*map_entry, "self", &map_feed_uri);
|
||||
std::cout << "Upload succeeded. Map feed URI: " << map_feed_uri
|
||||
<< std::endl;
|
||||
|
||||
if (Prompt::PromptAgain("Get CSV for another spreadsheet? ")) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Walk a KML NetworkLink hierarchy.
|
||||
// Fetches and parses the NetworkLinks in a given file recursively.
|
||||
// Prints a count of the number of KML files fetched and the total number
|
||||
// of each kind of Feature in the hierachy.
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/dom/xsd.h" // TODO: expose Xsd::ElementName() properly
|
||||
#include "kml/engine.h"
|
||||
#include "curlfetch.h"
|
||||
|
||||
using kmldom::ElementPtr;
|
||||
using kmldom::FeaturePtr;
|
||||
using kmldom::NetworkLinkPtr;
|
||||
using kmldom::OverlayPtr;
|
||||
using kmldom::StylePtr;
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
using kmlengine::KmlCache;
|
||||
using kmlengine::GetRootFeature;
|
||||
using kmlengine::VisitFeatureHierarchy;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
static void CountFeature(int type_id);
|
||||
static void PrintFeatureCounts();
|
||||
static void PrintFileCount();
|
||||
static void WalkKmlFile(const KmlFilePtr& kml_file);
|
||||
|
||||
static int file_count;
|
||||
static int feature_count;
|
||||
static size_t data_size;
|
||||
static size_t style_size;
|
||||
static size_t balloon_size;
|
||||
|
||||
static void PrintFileCount() {
|
||||
cout << "files " << file_count << endl;
|
||||
cout << "features " << feature_count << endl;
|
||||
cout << "data bytes " << data_size << endl;
|
||||
cout << "style bytes " << style_size << endl;
|
||||
cout << "balloon bytes " << balloon_size << endl;
|
||||
}
|
||||
|
||||
typedef std::map<int,int> feature_counter_t;
|
||||
feature_counter_t feature_counter;
|
||||
|
||||
static void CountFeature(int type_id) {
|
||||
++feature_count;
|
||||
feature_counter_t::const_iterator entry = feature_counter.find(type_id);
|
||||
if (entry == feature_counter.end()) {
|
||||
feature_counter[type_id] = 1;
|
||||
} else {
|
||||
++feature_counter[type_id];
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintFeatureCounts() {
|
||||
for (feature_counter_t::const_iterator iter = feature_counter.begin();
|
||||
iter != feature_counter.end(); ++iter) {
|
||||
std::string element_name;
|
||||
cout << kmldom::Xsd::GetSchema()->ElementName(iter->first) << " "
|
||||
<< iter->second << endl;
|
||||
}
|
||||
}
|
||||
|
||||
class FeatureCounter : public kmlengine::FeatureVisitor {
|
||||
public:
|
||||
FeatureCounter(const KmlFilePtr& kml_file)
|
||||
: kml_file_(kml_file) {}
|
||||
|
||||
virtual void VisitFeature(const kmldom::FeaturePtr& feature) {
|
||||
CountFeature(feature->Type());
|
||||
StylePtr style = CreateResolvedStyle(feature, kml_file_,
|
||||
kmldom::STYLESTATE_NORMAL);
|
||||
std::string style_string = kmldom::SerializePretty(style);
|
||||
style_size += style_string.size();
|
||||
std::string balloon_text = CreateBalloonText(kml_file_, feature);
|
||||
balloon_size += balloon_text.size();
|
||||
if (OverlayPtr overlay = AsOverlay(feature)) {
|
||||
std::string data;
|
||||
if (kmlengine::FetchIcon(kml_file_, overlay, &data)) {
|
||||
cout << " bytes " << data.size() << endl;
|
||||
data_size += data.size();
|
||||
} else {
|
||||
cout << "fetch failed " << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const KmlFilePtr kml_file_;
|
||||
};
|
||||
|
||||
static void HandleFile(const KmlFilePtr& kml_file) {
|
||||
cout << kml_file->get_url() << endl;
|
||||
++file_count;
|
||||
FeatureCounter feature_counter(kml_file);
|
||||
VisitFeatureHierarchy(GetRootFeature(kml_file->get_root()), feature_counter);
|
||||
}
|
||||
|
||||
static void WalkNetworkLinks(const KmlFilePtr& kml_file) {
|
||||
const kmlengine::ElementVector& link_vector =
|
||||
kml_file->get_link_parent_vector();
|
||||
for (size_t i = 0; i < link_vector.size(); ++i) {
|
||||
if (NetworkLinkPtr networklink = AsNetworkLink(link_vector[i])) {
|
||||
if (KmlFilePtr child = kmlengine::FetchLink(kml_file, networklink)) {
|
||||
WalkKmlFile(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void WalkKmlFile(const KmlFilePtr& kml_file) {
|
||||
// First walk through this KmlFile's Features.
|
||||
HandleFile(kml_file);
|
||||
// Then walk recursively through all of its NetworkLinks.
|
||||
WalkNetworkLinks(kml_file);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cout << "usage: " << argv[0] << " url" << endl;
|
||||
return 1;
|
||||
}
|
||||
const char* kml_url = argv[1];
|
||||
CurlNetFetcher curl_net_fetcher;
|
||||
KmlCache kml_cache(&curl_net_fetcher, 30);
|
||||
const KmlFilePtr kml_file = kml_cache.FetchKmlAbsolute(kml_url);
|
||||
if (!kml_file) {
|
||||
cerr << "failed: " << kml_url << endl;
|
||||
return 1;
|
||||
}
|
||||
WalkKmlFile(kml_file);
|
||||
PrintFileCount();
|
||||
PrintFeatureCounts();
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/engine.h"
|
||||
#include "curlfetch.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using kmlbase::File;
|
||||
using kmlengine::KmlCache;
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2 && argc != 3) {
|
||||
cout << "usage: " << argv[0] << " url.kml [relative]" << endl;
|
||||
cout << "usage: " << argv[0] << " url.kmz [relative]" << endl;
|
||||
cout << "usage: " << argv[0] << " url.kmz/path.kml [relative]" << endl;
|
||||
cout << "usage: " << argv[0] << " url.kmz/non-kml" << endl;
|
||||
return 1;
|
||||
}
|
||||
const char* url = argv[1];
|
||||
const char* relative = argc == 3 ? argv[2] : NULL;
|
||||
|
||||
CurlNetFetcher curl_net_fetcher;
|
||||
KmlCache kml_cache(&curl_net_fetcher, 1);
|
||||
if (relative) {
|
||||
std::string data;
|
||||
if (kml_cache.FetchDataRelative(url, relative, &data)) {
|
||||
cout << data;
|
||||
}
|
||||
} else {
|
||||
if (KmlFilePtr kml_file = kml_cache.FetchKmlAbsolute(url)) {
|
||||
std::string output;
|
||||
if (kml_file->SerializeToString(&output)) {
|
||||
cout << output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This prints every link and title in every entry in the given (Atom) feed.
|
||||
// See RFC 4287. The Atom file can either be a local file or a network URL.
|
||||
// (There is no direct relationship to KML in this program.)
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "curlfetch.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "usage: " << argv[0] << " feed-file-or-url.atom" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* feed_url = argv[1];
|
||||
|
||||
std::string feed_data;
|
||||
if (!kmlbase::File::ReadFileToString(feed_url, &feed_data) &&
|
||||
!CurlToString(feed_url, &feed_data)) {
|
||||
std::cerr << "read/fetch failed " << feed_url << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// This program expects a <feed> root element.
|
||||
kmldom::AtomFeedPtr feed = kmldom::AsAtomFeed(
|
||||
kmldom::ParseAtom(feed_data, NULL));
|
||||
if (!feed.get()) {
|
||||
std::cerr << "parse failed " << feed_url << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (size_t e = 0; e < feed->get_entry_array_size(); ++e) {
|
||||
// For each <entry> in the feed...
|
||||
const kmldom::AtomEntryPtr& entry = feed->get_entry_array_at(e);
|
||||
// Print the <title>:
|
||||
std::cout << "[title] " << entry->get_title() << std::endl;
|
||||
for (size_t l = 0; l < entry->get_link_array_size(); ++l) {
|
||||
// For each <link> in the entry...
|
||||
const kmldom::AtomLinkPtr& link = entry->get_link_array_at(l);
|
||||
// Print the href=:
|
||||
std::cout << " [link] " << link->get_href() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/convenience/atom_util.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/google_doc_list.h"
|
||||
|
||||
using kmlconvenience::AtomUtil;
|
||||
using kmlconvenience::GoogleDocList;
|
||||
using kmldom::AtomEntryPtr;
|
||||
using kmldom::AtomFeedPtr;
|
||||
using kmldom::AsAtomEntry;
|
||||
using kmldom::AsAtomFeed;
|
||||
using kmldom::ParseAtom;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string doc_title;
|
||||
|
||||
// Get the user logged in first.
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
CurlHttpClient* curl_http_client = new CurlHttpClient(
|
||||
"libkml:examples:hellonet:getgdoc");
|
||||
if (!curl_http_client->Login(GoogleDocList::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Login succeeded..." << std::endl;
|
||||
|
||||
// Create a GoogleDocList client from the logged in HttpClient and
|
||||
// get the user's list of Google docs.
|
||||
boost::scoped_ptr<kmlconvenience::GoogleDocList> doc_list(
|
||||
kmlconvenience::GoogleDocList::Create(curl_http_client));
|
||||
|
||||
kmldom::AtomFeedPtr meta_feed = doc_list->GetMetaFeed();
|
||||
if (!meta_feed.get()) {
|
||||
std::cerr << "GetMetaFeed failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "You have " << meta_feed->get_entry_array_size()
|
||||
<< " docs:" << std::endl;
|
||||
|
||||
for (size_t l = 0; l < meta_feed->get_entry_array_size(); ++l) {
|
||||
const kmldom::AtomEntryPtr& entry = meta_feed->get_entry_array_at(l);
|
||||
// TODO: implement FindCategoryByScheme
|
||||
#if 0
|
||||
kmldom::AtomCategoryPtr category = AtomUtil::FindCategoryByScheme(*entry,
|
||||
"kind");
|
||||
std::string kind = (category && category->has_label())
|
||||
? category->get_label() : "[unknown kind]";
|
||||
std::cout << kind << ": " << entry->get_title() << std::endl;
|
||||
#else
|
||||
std::cout << entry->get_title() << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This lists a users Google My Maps using the Google Maps Data API. The
|
||||
// list of maps is an Atom feed where each entry is a Google My Map.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
#include "kml/convenience/google_maps_data.h"
|
||||
|
||||
using kmlconvenience::GoogleMapsData;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string user;
|
||||
std::string password;
|
||||
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
CurlHttpClient* curl_http_client =
|
||||
new CurlHttpClient("libkml:examples:hellonet:listgmaps");
|
||||
if (!curl_http_client->Login(GoogleMapsData::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::scoped_ptr<GoogleMapsData> google_maps_data(
|
||||
GoogleMapsData::Create(curl_http_client));
|
||||
|
||||
kmldom::AtomFeedPtr meta_feed = google_maps_data->GetMetaFeed();
|
||||
if (!meta_feed.get()) {
|
||||
std::cerr << "GetMetaFeed failed" << std::endl;
|
||||
}
|
||||
|
||||
// For each <entry> in the <feed>...
|
||||
for (size_t e = 0; e < meta_feed->get_entry_array_size(); ++e) {
|
||||
const kmldom::AtomEntryPtr& entry = meta_feed->get_entry_array_at(e);
|
||||
// Print the <title>:
|
||||
std::cout << "[title] " << entry->get_title() << std::endl;
|
||||
std::string feature_feed_uri;
|
||||
if (GoogleMapsData::GetFeatureFeedUri(entry, &feature_feed_uri)) {
|
||||
std::cout << " [feature feed] " << feature_feed_uri << std::endl;
|
||||
}
|
||||
for (size_t l = 0; l < entry->get_link_array_size(); ++l) {
|
||||
// For each <link> in the entry...
|
||||
const kmldom::AtomLinkPtr& link = entry->get_link_array_at(l);
|
||||
// Print the rel= and href=.
|
||||
std::cout << " [rel ] " << link->get_rel() << std::endl;
|
||||
std::cout << " [href] " << link->get_href() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "You have " << meta_feed->get_entry_array_size() << " maps.";
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This lists a users Google Picasa Web Albums using the Google Picass Web
|
||||
// Albus Data API. The list of albums is an Atom feed where each entry
|
||||
// is a photo album.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
#include "kml/convenience/google_picasa_web.h"
|
||||
|
||||
using kmlconvenience::GooglePicasaWeb;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string user;
|
||||
std::string password;
|
||||
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
CurlHttpClient* curl_http_client =
|
||||
new CurlHttpClient("libkml:examples:hellonet:listgphotos");
|
||||
if (!curl_http_client->Login(GooglePicasaWeb::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::scoped_ptr<GooglePicasaWeb> google_picasa_web(
|
||||
GooglePicasaWeb::Create(curl_http_client));
|
||||
|
||||
kmldom::AtomFeedPtr meta_feed = google_picasa_web->GetMetaFeed();
|
||||
if (!meta_feed.get()) {
|
||||
std::cerr << "GetMetaFeed failed" << std::endl;
|
||||
}
|
||||
|
||||
// For each <entry> in the <feed>...
|
||||
for (size_t e = 0; e < meta_feed->get_entry_array_size(); ++e) {
|
||||
const kmldom::AtomEntryPtr& entry = meta_feed->get_entry_array_at(e);
|
||||
// Print the <title>:
|
||||
std::cout << "[title] " << entry->get_title() << std::endl;
|
||||
for (size_t l = 0; l < entry->get_link_array_size(); ++l) {
|
||||
// For each <link> in the entry...
|
||||
const kmldom::AtomLinkPtr& link = entry->get_link_array_at(l);
|
||||
// Print the href=:
|
||||
std::cout << " [link] " << link->get_href() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "You have " << meta_feed->get_entry_array_size() << " albums.";
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file contains the Prompt class.
|
||||
|
||||
#ifndef EXAMPLES_HELLONET_PROMPT_H__
|
||||
#define EXAMPLES_HELLONET_PROMPT_H__
|
||||
|
||||
#include <termios.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
// This class provides some static methods useful for prompting on a terminal.
|
||||
class Prompt {
|
||||
public:
|
||||
static std::string PromptAndInputWithNoEcho(const std::string& prompt) {
|
||||
std::cin.get();
|
||||
std::cout << prompt;
|
||||
std::cout << std::flush;
|
||||
// Get the current state of the input terminal.
|
||||
struct termios t;
|
||||
tcgetattr(0, &t);
|
||||
// Flip off the ECHO bit.
|
||||
t.c_lflag &= ~ECHO;
|
||||
tcsetattr(0, TCSANOW, &t);
|
||||
// User can now type password safely.
|
||||
std::string input;
|
||||
std::getline(std::cin, input);
|
||||
// Flip ECHO back on.
|
||||
t.c_lflag |= ECHO;
|
||||
tcsetattr(0, TCSANOW, &t);
|
||||
std::cout << std::endl;
|
||||
return input;
|
||||
}
|
||||
|
||||
static bool PromptAgain(const std::string& prompt) {
|
||||
std::cout << prompt;
|
||||
std::string again;
|
||||
std::getline(std::cin, again);
|
||||
return !again.empty() && again[0] == 'y';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // EXAMPLES_HELLONET_PROMPT_H__
|
|
@ -0,0 +1,85 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program makes some basic use of the KML Engine
|
||||
// CreateNetworkResolvedStyle() function. For example:
|
||||
/*
|
||||
resolvestyle \
|
||||
http://kml-samples.googlecode.com/svn/trunk/kml/Style/remote-style.kml \
|
||||
radio-relative|radio-absolute
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "curlfetch.h"
|
||||
|
||||
using kmldom::FeaturePtr;
|
||||
using kmldom::StylePtr;
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
|
||||
// This prints out the normal <Style> for the feature of the given id in the
|
||||
// given KML file.
|
||||
void HelloCreateResolvedStyle(const std::string& kml_url,
|
||||
const std::string& id) {
|
||||
// Networked style resolution requires a KmlCache to fetch through.
|
||||
CurlNetFetcher curl_net_fetcher;
|
||||
kmlengine::KmlCache kml_cache(&curl_net_fetcher, 2);
|
||||
|
||||
// KmlCache fetches this URL using the supplied CurlNetFetcher,
|
||||
// parses the KML into a KmlFile, and sets the URL and KmlCache
|
||||
// of the KmlFile.
|
||||
const KmlFilePtr kml_file = kml_cache.FetchKmlAbsolute(kml_url);
|
||||
if (!kml_file) {
|
||||
std::cerr << "parse or fetch failed: " << kml_url << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Look up the Feature
|
||||
const FeaturePtr feature = kmldom::AsFeature(kml_file->GetObjectById(id));
|
||||
if (!feature) {
|
||||
std::cerr << "no feature with id: " << id << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a resolved style for the Feature and print it.
|
||||
// Since this KmlFile came from a KmlCache CreateResolvedStyle()
|
||||
// will fetch any remote styleUrl's through this KmlCache.
|
||||
StylePtr style = kmlengine::CreateResolvedStyle(
|
||||
feature, kml_file, kmldom::STYLESTATE_NORMAL);
|
||||
std::cout << kmldom::SerializePretty(style);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "usage: " << argv[0] << "kmlfile feature-id" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
HelloCreateResolvedStyle(argv[1], argv[2]);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,178 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This returns the part of a My Map within the specified bounds. This is
|
||||
// interactive program which lists the users maps, asks for one by name,
|
||||
// and returns the features in that map within a bounding box specified by
|
||||
// the bounds of a KML file the user supplies. Any KML file can be used to
|
||||
// specify these bounds, for example one with a 2 vertex line will specify
|
||||
// the smallest north-up bounding box around that line.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/convenience/atom_util.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
#include "kml/convenience/google_maps_data.h"
|
||||
|
||||
using kmlconvenience::GoogleMapsData;
|
||||
|
||||
// This returns the bounding box of the given KML file.
|
||||
static bool GetMapBounds(const std::string map_name, kmlengine::Bbox* bbox) {
|
||||
if (!kmlbase::StringEndsWith(map_name, ".kml")) {
|
||||
std::cerr << "Specify a KML file." << std::endl;
|
||||
return false;
|
||||
} // TODO: else look for a My Map by this name
|
||||
std::string kml_data;
|
||||
if (!kmlbase::File::ReadFileToString(map_name, &kml_data)) {
|
||||
std::cerr << "Read failed: " << map_name << std::endl;
|
||||
return false;
|
||||
}
|
||||
kmlengine::KmlFilePtr kml_file(
|
||||
kmlengine::KmlFile::CreateFromParse(kml_data, NULL));
|
||||
if (!kml_file.get()) {
|
||||
std::cerr << "Parse failed: " << map_name << std::endl;
|
||||
return false;
|
||||
}
|
||||
kmldom::FeaturePtr root = kmlengine::GetRootFeature(kml_file->get_root());
|
||||
if (!root.get()) {
|
||||
std::cerr << "No root feature? " << map_name << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (!kmlengine::GetFeatureBounds(root, bbox)) {
|
||||
std::cerr << "No location info? " << map_name << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc > 1 ) {
|
||||
std::cerr << "Warning: this is an interactive program." << std::endl;
|
||||
std::cerr << "All command line args are ignored." << std::endl;
|
||||
}
|
||||
|
||||
std::string user;
|
||||
std::string password;
|
||||
|
||||
// Get the user logged in first.
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
CurlHttpClient* curl_http_client = new CurlHttpClient(
|
||||
"libkml:examples:hellonet:getmapkml");
|
||||
if (!curl_http_client->Login(GoogleMapsData::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Login succeeded..." << std::endl;
|
||||
|
||||
// Create a GoogleMapsData client from the logged in HttpClient and
|
||||
// get the user's list of maps.
|
||||
boost::scoped_ptr<GoogleMapsData> google_maps_data(
|
||||
GoogleMapsData::Create(curl_http_client));
|
||||
kmldom::AtomFeedPtr meta_feed = google_maps_data->GetMetaFeed();
|
||||
if (!meta_feed.get()) {
|
||||
std::cerr << "GetMetaFeed failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
again:
|
||||
std::cout << "You have " << meta_feed->get_entry_array_size() << " maps."
|
||||
<< std::endl;
|
||||
|
||||
for (size_t l = 0; l < meta_feed->get_entry_array_size(); ++l) {
|
||||
const kmldom::AtomEntryPtr& entry = meta_feed->get_entry_array_at(l);
|
||||
std::cout << entry->get_title() << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Title of map to search: ";
|
||||
// Use std::getline here to capture the entire line.
|
||||
std::string map_title;
|
||||
std::getline(std::cin, map_title);
|
||||
|
||||
const kmldom::AtomEntryPtr& map_entry =
|
||||
kmlconvenience::AtomUtil::FindEntryByTitle(meta_feed, map_title);
|
||||
|
||||
if (!map_entry.get()) {
|
||||
std::cout << "No map with title: " << map_title << std::endl;
|
||||
if (Prompt::PromptAgain("Try another title? ")) {
|
||||
goto again;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
kml_again:
|
||||
std::cout << "Bounds KML: ";
|
||||
// Use std::getline here to capture the entire line.
|
||||
std::string bounds_map;
|
||||
std::getline(std::cin, bounds_map);
|
||||
|
||||
kmlengine::Bbox bbox;
|
||||
if (!GetMapBounds(bounds_map, &bbox)) {
|
||||
goto kml_again;
|
||||
}
|
||||
|
||||
const kmldom::AtomFeedPtr feature_feed = google_maps_data->SearchMapByBbox(
|
||||
map_entry, bbox);
|
||||
|
||||
std::cout << "There are " << feature_feed->get_entry_array_size()
|
||||
<< " features in this bounding box." << std::endl;
|
||||
|
||||
std::cout << "Output file: ";
|
||||
std::string output;
|
||||
std::cin >> output;
|
||||
|
||||
// Dig out the KML features in the feed and put them in a <Document>.
|
||||
kmldom::KmlPtr kml = kmldom::KmlFactory::GetFactory()->CreateKml();
|
||||
kmldom::ContainerPtr container =
|
||||
google_maps_data->CreateDocumentOfMapFeatures(feature_feed);
|
||||
kml->set_feature(container);
|
||||
|
||||
std::cout << "There are " << container->get_feature_array_size()
|
||||
<< " Features in the map saved to " << output << "." << std::endl;
|
||||
|
||||
// Use KmlFile's serialize to get xml proper header and xmlns.
|
||||
boost::scoped_ptr<kmlengine::KmlFile> kml_file(
|
||||
kmlengine::KmlFile::CreateFromImport(kml));
|
||||
std::string xml;
|
||||
kml_file->SerializeToString(&xml);
|
||||
kmlbase::File::WriteStringToFile(xml, output.c_str());
|
||||
|
||||
std::cin.get();
|
||||
if (Prompt::PromptAgain("Get KML for another map? ")) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This creates a new Google My Map from the given KML file using the Google
|
||||
// Maps Data API. The URI of feed to the new map is printed on output.
|
||||
// The created map has only the Placemarks from the original file.
|
||||
|
||||
#include <termios.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/convenience/atom_util.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/google_maps_data.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
|
||||
using kmlconvenience::GoogleMapsData;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
std::cout << "usage: " << argv[0] << " file.kml" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string kml_data;
|
||||
if (!kmlbase::File::ReadFileToString(argv[1], &kml_data)) {
|
||||
std::cerr << "Read failed: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse the KML and inline all StyleSelectors.
|
||||
const kmldom::FeaturePtr root_feature =
|
||||
kmlengine::GetRootFeature(kmlengine::InlineStyles(kml_data, NULL));
|
||||
if (!root_feature.get()) {
|
||||
std::cerr << "No root feature?" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string user;
|
||||
std::string password;
|
||||
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
CurlHttpClient* curl_http_client =
|
||||
new CurlHttpClient("libkml:examples:hellonet::uploadgmap");
|
||||
if (!curl_http_client->Login(GoogleMapsData::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::scoped_ptr<GoogleMapsData> google_maps_data(
|
||||
GoogleMapsData::Create(curl_http_client));
|
||||
|
||||
std::string map_entry_xml;
|
||||
google_maps_data->CreateMap(root_feature->get_name(),
|
||||
root_feature->get_description(), &map_entry_xml);
|
||||
|
||||
kmldom::AtomEntryPtr map_entry =
|
||||
kmldom::AsAtomEntry(kmldom::ParseAtom(map_entry_xml, NULL));
|
||||
if (!map_entry.get()) {
|
||||
// A parse failure usually means a non-xml error string was returned as
|
||||
// the response.
|
||||
std::cerr << "CreateMap failed: " << map_entry_xml << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Print the map feed URI now because Google Maps Data API does not show
|
||||
// maps with no features in the list of maps.
|
||||
// TODO: delete the map if no features were added?
|
||||
std::string map_feed_uri;
|
||||
kmlconvenience::AtomUtil::FindRelUrl(*map_entry, "self", &map_feed_uri);
|
||||
std::cout << "Map feed URI: " << map_feed_uri << std::endl;
|
||||
|
||||
std::string feature_feed_uri;
|
||||
if (!GoogleMapsData::GetFeatureFeedUri(map_entry, &feature_feed_uri)) {
|
||||
std::cerr << "No Feature feed URI?" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int placemark_count = google_maps_data->PostPlacemarks(root_feature,
|
||||
feature_feed_uri);
|
||||
std::cout << "Uploaded " << placemark_count << " placemarks." << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
// Copyright 2010, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/convenience/google_maps_data.h"
|
||||
|
||||
using kmlconvenience::GoogleMapsData;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 3) {
|
||||
std::cout << "usage: " << argv[0] << " file.csv title" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
const char* csv_file = argv[1];
|
||||
const char* title = argv[2];
|
||||
|
||||
std::string csv_data;
|
||||
if (!kmlbase::File::ReadFileToString(csv_file, &csv_data)) {
|
||||
std::cerr << "Read failed: " << csv_file << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string user;
|
||||
std::string password;
|
||||
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
CurlHttpClient* curl_http_client =
|
||||
new CurlHttpClient("libkml:examples:hellonet::uploadgmapcsv");
|
||||
if (!curl_http_client->Login(GoogleMapsData::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::scoped_ptr<GoogleMapsData> google_maps_data(
|
||||
GoogleMapsData::Create(curl_http_client));
|
||||
|
||||
string errors;
|
||||
kmldom::AtomEntryPtr map_entry = google_maps_data->PostCsv(title, csv_data,
|
||||
&errors);
|
||||
// If the PostCsv fails it may be due to CSV errors.
|
||||
if (!map_entry.get()) {
|
||||
std::cerr << "PostCsv failed:" << std::endl;
|
||||
std::cerr << errors << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// PostCsv succeeded: print the link to the KML of the new map.
|
||||
std::string kml_uri;
|
||||
google_maps_data->GetKmlUri(map_entry, &kml_uri);
|
||||
std::cout << "Upload succeeded. Map KML URI: " << kml_uri << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
// Copyright 2010, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <termios.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/convenience/atom_util.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/google_maps_data.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
|
||||
using kmlconvenience::GoogleMapsData;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
std::cout << "usage: " << argv[0] << " file.kml" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* kml_file = argv[1];
|
||||
std::string kml_data;
|
||||
if (!kmlbase::File::ReadFileToString(kml_file, &kml_data)) {
|
||||
std::cerr << "Read failed: " << kml_file << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string user;
|
||||
std::string password;
|
||||
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
CurlHttpClient* curl_http_client =
|
||||
new CurlHttpClient("libkml:examples:hellonet:uploadgmapkml");
|
||||
if (!curl_http_client->Login(GoogleMapsData::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::scoped_ptr<GoogleMapsData> google_maps_data(
|
||||
GoogleMapsData::Create(curl_http_client));
|
||||
|
||||
// Use the filename as the Maps Data API title.
|
||||
kmldom::AtomEntryPtr map_entry = google_maps_data->PostKml(kml_file,
|
||||
kml_data);
|
||||
if (!map_entry.get()) {
|
||||
// A parse failure usually means a non-xml error string was returned as
|
||||
// the response.
|
||||
std::cerr << "PostKml failed" << kml_file << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// PostKml succeeded: print the link to the KML of the new map.
|
||||
std::string kml_uri;
|
||||
google_maps_data->GetKmlUri(map_entry, &kml_uri);
|
||||
std::cout << "Upload succeeded. Map KML URI: " << kml_uri << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <termios.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "prompt.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/convenience/atom_util.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
#include "kml/convenience/google_doc_list.h"
|
||||
#include "kml/convenience/http_client.h"
|
||||
|
||||
using kmlconvenience::GoogleDocList;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
std::cout << "usage: " << argv[0] << " file.csv" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string spreadsheet_data;
|
||||
if (!kmlbase::File::ReadFileToString(argv[1], &spreadsheet_data)) {
|
||||
std::cerr << "Read failed: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string user;
|
||||
std::string password;
|
||||
|
||||
std::cout << "Email: ";
|
||||
std::cin >> user;
|
||||
password = Prompt::PromptAndInputWithNoEcho("Password: ");
|
||||
|
||||
// Yes, you use Doc List API to upload a spreadsheet.
|
||||
CurlHttpClient* curl_http_client =
|
||||
new CurlHttpClient("libkml:examples:hellonet::uploadgsheet");
|
||||
if (!curl_http_client->Login(GoogleDocList::get_service_name(), user,
|
||||
password)) {
|
||||
std::cerr << "Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::scoped_ptr<GoogleDocList> google_doc_list(
|
||||
GoogleDocList::Create(curl_http_client));
|
||||
|
||||
// TODO: add a Slug: header to set the title.
|
||||
std::string doc_entry_xml;
|
||||
if (!google_doc_list->UploadSpreadsheet(spreadsheet_data, "text/csv",
|
||||
&doc_entry_xml)) {
|
||||
std::cerr << "UploadSpreadsheet failed: " << doc_entry_xml << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
kmldom::AtomEntryPtr map_entry =
|
||||
kmldom::AsAtomEntry(kmldom::ParseAtom(doc_entry_xml, NULL));
|
||||
if (!map_entry.get()) {
|
||||
// A parse failure usually means a non-xml error string was returned as
|
||||
// the response.
|
||||
std::cerr << "CreateMap failed: " << doc_entry_xml << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string doc_feed_uri;
|
||||
kmlconvenience::AtomUtil::FindRelUrl(*map_entry, "self", &doc_feed_uri);
|
||||
std::cout << "Upload succeeded. Doc feed URI: " << doc_feed_uri
|
||||
<< std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "curlfetch.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "kml/xsd/xsd_complex_type.h"
|
||||
#include "kml/xsd/xsd_file.h"
|
||||
#include "kml/xsd/xsd_simple_type.h"
|
||||
#include "kml/xsd/xsd_util.h"
|
||||
|
||||
using kmlxsd::XsdComplexType;
|
||||
using kmlxsd::XsdComplexTypePtr;
|
||||
using kmlxsd::XsdElementPtr;
|
||||
using kmlxsd::XsdElementVector;
|
||||
using kmlxsd::XsdFile;
|
||||
using kmlxsd::XsdSimpleType;
|
||||
using kmlxsd::XsdSimpleTypePtr;
|
||||
using kmlxsd::XsdType;
|
||||
using kmlxsd::XsdTypePtr;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::vector;
|
||||
|
||||
static const char kOgcKml22Xsd[] =
|
||||
"http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd";
|
||||
|
||||
static void PrintElement(const XsdFile& xsd_file, const XsdElementPtr element) {
|
||||
const XsdTypePtr& xsd_type = xsd_file.FindElementType(element);
|
||||
if (XsdComplexTypePtr complex_type =
|
||||
XsdComplexType::AsComplexType(xsd_type)) {
|
||||
cout << element->get_name() << " " << element->get_type() << endl;
|
||||
if (const XsdComplexTypePtr base = xsd_file.GetBaseType(complex_type)) {
|
||||
cout << " is-a " << base->get_name() << endl;
|
||||
}
|
||||
XsdElementVector children;
|
||||
xsd_file.GetChildElements(element->get_name(), &children);
|
||||
for (size_t i = 0; i < children.size(); ++i) {
|
||||
if (children[i]) { // TODO hack due to atom:author
|
||||
cout << " " << children[i]->get_name() << " "
|
||||
<< children[i]->get_type() << " [" << children[i]->get_default()
|
||||
<< "]" << endl;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (XsdSimpleTypePtr simple_type = XsdSimpleType::AsSimpleType(xsd_type)) {
|
||||
cout << element->get_name() << " " << element->get_type() << endl;
|
||||
if (simple_type->IsEnumeration()) {
|
||||
cout << " is an enum" << endl;
|
||||
for (size_t i = 0; i < simple_type->get_enumeration_size(); ++i) {
|
||||
cout << " " << simple_type->get_enumeration_at(i) << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc > 2) {
|
||||
cerr << "usage: " << argv[0] << " [url-to-kml.xsd]" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* kml_xsd_url = argc > 1 ? argv[1] : kOgcKml22Xsd;
|
||||
|
||||
std::string xsd_data;
|
||||
if (!kmlbase::File::ReadFileToString(kml_xsd_url, &xsd_data) &&
|
||||
!CurlToString(kml_xsd_url, &xsd_data)) {
|
||||
// TODO: parse kml_xsd_url to determine local/remote
|
||||
cerr << "read/fetch failed " << kml_xsd_url << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string errors;
|
||||
boost::scoped_ptr<XsdFile> xsd_file(
|
||||
XsdFile::CreateFromParse(xsd_data, &errors));
|
||||
if (!xsd_file.get()) {
|
||||
cerr << "parse failed " << errors;
|
||||
return 1;
|
||||
}
|
||||
|
||||
kmlxsd::XsdElementVector elements;
|
||||
xsd_file->GetAllElements(&elements);
|
||||
for (size_t i = 0; i < elements.size(); ++i) {
|
||||
PrintElement(*xsd_file, elements[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
add_library(helloutil print.cc)
|
||||
target_link_libraries(helloutil ${MINIZIP_LIBRARY})
|
||||
|
||||
build_example(
|
||||
NAME createkml
|
||||
DEPENDS kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME circlegen
|
||||
DEPENDS kmlconvenience kmlengine kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME checklinks
|
||||
DEPENDS kmlengine kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME countkml
|
||||
DEPENDS kmlengine kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME helloattrs
|
||||
DEPENDS kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME helloenum
|
||||
DEPENDS kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME hellofeatures
|
||||
DEPENDS kmldom kmlbase helloutil)
|
||||
|
||||
build_example(
|
||||
NAME hellofolder
|
||||
DEPENDS kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME hellogeometry
|
||||
DEPENDS kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME hellohref
|
||||
DEPENDS kmldom kmlbase helloutil)
|
||||
|
||||
build_example(
|
||||
NAME hellokmz
|
||||
DEPENDS kmldom kmlbase kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME helloregion
|
||||
DEPENDS kmldom kmlbase helloutil)
|
||||
|
||||
build_example(
|
||||
NAME helloworld
|
||||
DEPENDS kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME parsekml
|
||||
DEPENDS kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME parsens
|
||||
DEPENDS kmldom kmlbase)
|
||||
|
||||
build_example(
|
||||
NAME prettykml
|
||||
DEPENDS kmldom kmlbase kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME printgeometry
|
||||
DEPENDS kmldom kmlbase kmlengine)
|
||||
|
||||
build_example(
|
||||
NAME sharedstyles
|
||||
DEPENDS kmldom kmlbase kmlengine kmlconvenience)
|
||||
|
||||
build_example(
|
||||
NAME simplifylines
|
||||
DEPENDS kmldom kmlbase kmlengine kmlconvenience)
|
||||
|
||||
build_example(
|
||||
NAME sortplacemarks
|
||||
DEPENDS kmldom kmlbase kmlengine kmlconvenience)
|
||||
|
||||
|
||||
if(INSTALL_EXAMPLES)
|
||||
file(GLOB eg_files "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
|
||||
install(FILES ${eg_files} DESTINATION ${KML_EXAMPLES_DIR} COMPONENT Development)
|
||||
install(FILES print.h
|
||||
DESTINATION ${KML_EXAMPLES_DIR}
|
||||
COMPONENT Development)
|
||||
endif()
|
|
@ -0,0 +1,116 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program uses ParserObserver::AddChild() to discover all URLs
|
||||
// in a KML file. A potentially fetchable URL is found in all <href>'s,
|
||||
// Model/Alias/targetHref, Feature/styleUrl, and SchemaData/schemaUrl=.
|
||||
// TODO: balloons have HTML <img src=".."> and <a href="..."> links.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/base/file.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using kmldom::ElementPtr;
|
||||
using kmlengine::KmzFile;
|
||||
|
||||
class PrintLinks : public kmldom::ParserObserver {
|
||||
public:
|
||||
virtual bool AddChild(const ElementPtr& parent, const ElementPtr& child) {
|
||||
switch (child->Type()) {
|
||||
case kmldom::Type_href:
|
||||
// NetworkLink/Link/href, Overlay/Icon/href, ItemIcon/href
|
||||
// Model/Link/href, IconStyle/Icon/href
|
||||
cout << "href=" << child->get_char_data() << endl;
|
||||
break;
|
||||
case kmldom::Type_targetHref:
|
||||
if (kmldom::Type_Alias == parent->Type()) {
|
||||
cout << "Alias/targetHref=" << child->get_char_data() << endl;
|
||||
}
|
||||
break;
|
||||
case kmldom::Type_styleUrl:
|
||||
cout << "styleUrl=" << child->get_char_data() << endl;
|
||||
break;
|
||||
case kmldom::Type_SchemaData:
|
||||
{ // Avoid 'jump to case label croses initialization' compiler warning.
|
||||
kmldom::SchemaDataPtr schemadata = kmldom::AsSchemaData(child);
|
||||
if (schemadata->has_schemaurl()) {
|
||||
cout << "schemaUrl=" << schemadata->get_schemaurl() << endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
// TODO: HTML links in description and BalloonStyle/text
|
||||
default: break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cout << "usage: " << argv[0] << " input.kml" << endl;
|
||||
return 1;
|
||||
}
|
||||
const char* kmlfile = argv[1];
|
||||
|
||||
// Read the file.
|
||||
std::string file_data;
|
||||
if (!kmlbase::File::ReadFileToString(kmlfile, &file_data)) {
|
||||
cout << kmlfile << " read failed" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// If the file was KMZ, extract the KML file.
|
||||
std::string kml;
|
||||
if (KmzFile::IsKmz(file_data)) {
|
||||
boost::scoped_ptr<KmzFile> kmz_file(KmzFile::OpenFromString(file_data));
|
||||
if (!kmz_file.get()) {
|
||||
cout << "Failed opening KMZ file" << endl;
|
||||
return 1;
|
||||
}
|
||||
if (!kmz_file->ReadKml(&kml)) {
|
||||
cout << "Failed to read KML from KMZ" << endl;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
kml = file_data;
|
||||
}
|
||||
|
||||
// Parse it.
|
||||
kmldom::Parser parser;
|
||||
PrintLinks print_links;
|
||||
parser.AddObserver(&print_links);
|
||||
std::string errors;
|
||||
ElementPtr root = parser.Parse(kml, &errors);
|
||||
if (!root) {
|
||||
cout << errors << endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
// Copyright 2009, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This sample program creates a polygon representation of a great circle.
|
||||
// You can define the circle either by a point and a radius from that point,
|
||||
// or by a central point and a point on the circumference.
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/base/math_util.h"
|
||||
#include "kml/base/vec3.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::LinearRingPtr;
|
||||
using kmldom::CoordinatesPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
// The number of lines composing the circumference of the circle.
|
||||
static const size_t kSegments = 360;
|
||||
|
||||
// Creates a LinearRing that is the great circle described by a constant
|
||||
// radius from lat, lng.
|
||||
static LinearRingPtr CircleFromPointAndRadius(double lat, double lng,
|
||||
double radius) {
|
||||
CoordinatesPtr coords = kmlconvenience::CreateCoordinatesCircle(
|
||||
lat, lng, radius, kSegments);
|
||||
LinearRingPtr lr = KmlFactory::GetFactory()->CreateLinearRing();
|
||||
lr->set_coordinates(coords);
|
||||
return lr;
|
||||
}
|
||||
|
||||
// Creates a LinearRing that is the great circle described by a circumfrential
|
||||
// point (circum_lat, circum_lng) from a central point (center_lat,
|
||||
// center_lng).
|
||||
static LinearRingPtr CircleFromTwoPoints(double center_lat, double center_lng,
|
||||
double circum_lat, double circum_lng) {
|
||||
double radius = kmlbase::DistanceBetweenPoints(center_lat, center_lng,
|
||||
circum_lat, circum_lng);
|
||||
return CircleFromPointAndRadius(center_lat, center_lng, radius);
|
||||
}
|
||||
|
||||
// Generate the Polygon circle and print to stdout.
|
||||
static int PrintPlacemarkCircle(LinearRingPtr lr) {
|
||||
PlacemarkPtr p = kmlconvenience::CreateBasicPolygonPlacemark(lr);
|
||||
cout << kmldom::SerializePretty(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DoPointRadius(double lat, double lng, double radius) {
|
||||
LinearRingPtr lr = CircleFromPointAndRadius(lat, lng, radius);
|
||||
return PrintPlacemarkCircle(lr);
|
||||
}
|
||||
|
||||
static int DoTwoPoints(double lat1, double lng1, double lat2, double lng2) {
|
||||
LinearRingPtr lr = CircleFromTwoPoints(lat1, lng1, lat2, lng2);
|
||||
return PrintPlacemarkCircle(lr);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc !=4 && argc !=5 ) {
|
||||
cerr << "Supply either a central point (lat, lng in decimal degrees) " <<
|
||||
"and a radius (in meters) OR a central point and a point on " <<
|
||||
"the circumference" << endl;
|
||||
cerr << "usage: " << argv[0] << " center-lat center-lng radius" << endl;
|
||||
cerr << "usage: " << argv[0] << " center-lat center-lng circum-lat " <<
|
||||
"circum-lng" << endl;
|
||||
cerr << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
double center_lat = strtod(argv[1], NULL);
|
||||
double center_lng = strtod(argv[2], NULL);
|
||||
if (argc == 4) {
|
||||
double radius = strtod(argv[3], NULL);
|
||||
return DoPointRadius(center_lat, center_lng, radius);
|
||||
}
|
||||
if (argc == 5) {
|
||||
double circum_lat = strtod(argv[3], NULL);
|
||||
double circum_lng = strtod(argv[4], NULL);
|
||||
return DoTwoPoints(center_lat, center_lng, circum_lat, circum_lng);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This sample program uses a ParserObserver which counts element usage
|
||||
// in the given KML or KMZ file.
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/dom/xsd.h" // TODO: consider the Xsd class public?
|
||||
#include "kml/engine.h"
|
||||
#include "kml/base/file.h"
|
||||
|
||||
using kmlengine::KmzFile;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
// This map is used to hold the occurrence count for each element.
|
||||
typedef std::map<kmldom::KmlDomType, int> element_count_map_t;
|
||||
|
||||
// This ParserObserver uses the NewElement() method to count the number of
|
||||
// ocurrences of each type of element.
|
||||
class ElementCounter : public kmldom::ParserObserver {
|
||||
public:
|
||||
// ParserObserver::NewElement()
|
||||
virtual bool NewElement(const kmldom::ElementPtr& element) {
|
||||
if (element_count_map_.find(element->Type()) == element_count_map_.end()) {
|
||||
element_count_map_[element->Type()] = 1;
|
||||
} else {
|
||||
element_count_map_[element->Type()] += 1;
|
||||
}
|
||||
return true; // Always return true to keep parsing.
|
||||
}
|
||||
|
||||
// This method prints a summary of the internal element counting map.
|
||||
void PrintElementCounts() const {
|
||||
int total_element_count = 0;
|
||||
element_count_map_t::const_iterator map_iter;
|
||||
for (map_iter = element_count_map_.begin();
|
||||
map_iter != element_count_map_.end();
|
||||
++map_iter) {
|
||||
cout << kmldom::Xsd::GetSchema()->ElementName((*map_iter).first)
|
||||
<< " " << (*map_iter).second << endl;
|
||||
total_element_count += (*map_iter).second;
|
||||
}
|
||||
cout << "Element types " << element_count_map_.size() << endl;
|
||||
cout << "Total elements " << total_element_count << endl;
|
||||
}
|
||||
|
||||
private:
|
||||
element_count_map_t element_count_map_;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cout << "usage: " << argv[0] << " kmlfile" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read the file.
|
||||
std::string file_data;
|
||||
if (!kmlbase::File::ReadFileToString(argv[1], &file_data)) {
|
||||
cout << argv[1] << " read failed" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// If the file was KMZ, extract the KML file.
|
||||
std::string kml;
|
||||
if (KmzFile::IsKmz(file_data)) {
|
||||
boost::scoped_ptr<KmzFile> kmz_file(KmzFile::OpenFromString(file_data));
|
||||
if (!kmz_file.get()) {
|
||||
cout << "Failed opening KMZ file" << endl;
|
||||
return 1;
|
||||
}
|
||||
if (!kmz_file->ReadKml(&kml)) {
|
||||
cout << "Failed to read KML from KMZ" << endl;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
kml = file_data;
|
||||
}
|
||||
|
||||
// Parse it with the ElementCounter installed as a ParseObserver.
|
||||
kmldom::Parser parser;
|
||||
ElementCounter element_counter;
|
||||
parser.AddObserver(&element_counter);
|
||||
std::string errors;
|
||||
kmldom::ElementPtr root = parser.Parse(kml, &errors);
|
||||
if (!root) {
|
||||
cout << errors << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Ask the ElementCounter to print out what it observed.
|
||||
element_counter.PrintElementCounts();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// createkml.cc
|
||||
// This program uses the KmlFactory to create a Point Placemark and
|
||||
// prints the resultant KML on standard output.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
|
||||
// libkml types are in the kmldom namespace
|
||||
using kmldom::CoordinatesPtr;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmldom::PointPtr;
|
||||
|
||||
int main() {
|
||||
// Get the factory singleton to create KML elements.
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
|
||||
// Create <coordinates>.
|
||||
CoordinatesPtr coordinates = factory->CreateCoordinates();
|
||||
// Create <coordinates>-122.0816695,37.42052549<coordinates>
|
||||
coordinates->add_latlng(37.42052549,-122.0816695);
|
||||
|
||||
// Create <Point> and give it <coordinates>.
|
||||
PointPtr point = factory->CreatePoint();
|
||||
point->set_coordinates(coordinates); // point takes ownership
|
||||
|
||||
// Create <Placemark> and give it a <name> and the <Point>.
|
||||
PlacemarkPtr placemark = factory->CreatePlacemark();
|
||||
placemark->set_name("Cool Statue");
|
||||
placemark->set_geometry(point); // placemark takes ownership
|
||||
|
||||
// Create <kml> and give it <Placemark>.
|
||||
KmlPtr kml = factory->CreateKml();
|
||||
kml->set_feature(placemark); // kml takes ownership.
|
||||
|
||||
// Serialize to XML
|
||||
std::string xml = kmldom::SerializePretty(kml);
|
||||
|
||||
// Print to stdout
|
||||
std::cout << xml;
|
||||
}
|
|
@ -0,0 +1,207 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="createkml"
|
||||
ProjectGUID="{2D08AB30-4254-479F-9EF0-67E5C1EE2E64}"
|
||||
RootNamespace="createkml"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\third_party\boost_1_34_1;..\..\src"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="libkmlbase.lib libkmldom.lib libexpat.lib"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="C:\Program Files\Expat 2.0.1\Bin;..\..\debug"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\third_party\boost_1_34_1;..\..\src"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="libkmlbase.lib libkmldom.lib libexpat.lib"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
AdditionalLibraryDirectories="C:\Program Files\Expat 2.0.1\Bin;..\..\release"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath="createkml.cc"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
|
@ -0,0 +1,90 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Sample of parse and DOM access of attributes.
|
||||
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
|
||||
using kmldom::ElementPtr;
|
||||
using kmldom::HotSpotPtr;
|
||||
using kmldom::IconStylePtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
void CheckHotSpot() {
|
||||
const std::string kml(
|
||||
"<IconStyle id=\"is42\">"
|
||||
"<hotSpot x=\"0.5\" y=\"123\" xunits=\"fraction\" yunits=\"pixels\"/>"
|
||||
"</IconStyle>");
|
||||
ElementPtr root = kmldom::Parse(kml, NULL);
|
||||
|
||||
// Verify the parse went fine.
|
||||
assert(root); // The kml is perfect.
|
||||
|
||||
const IconStylePtr iconstyle = kmldom::AsIconStyle(root);
|
||||
assert(true == iconstyle->has_hotspot());
|
||||
|
||||
const HotSpotPtr hotspot = iconstyle->get_hotspot();
|
||||
assert(true == hotspot->has_x());
|
||||
assert(0.5 == hotspot->get_x());
|
||||
assert(true == hotspot->has_y());
|
||||
assert(123 == hotspot->get_y());
|
||||
assert(true == hotspot->has_xunits());
|
||||
assert(kmldom::UNITS_FRACTION == hotspot->get_xunits());
|
||||
assert(true == hotspot->has_yunits());
|
||||
assert(kmldom::UNITS_PIXELS == hotspot->get_yunits());
|
||||
|
||||
// Serialize the sample.
|
||||
std::string parsed_kml = kmldom::SerializePretty(hotspot);
|
||||
cout << parsed_kml << endl;
|
||||
}
|
||||
|
||||
void CheckId() {
|
||||
// Parse some KML with an attribute.
|
||||
const std::string kml(
|
||||
"<Placemark id=\"placemark123\"><name>x</name></Placemark>");
|
||||
ElementPtr root = kmldom::Parse(kml, NULL);
|
||||
|
||||
// Verify the parse went fine.
|
||||
assert(root); // The kml is perfect.
|
||||
|
||||
const PlacemarkPtr placemark = kmldom::AsPlacemark(root);
|
||||
|
||||
assert("placemark123" == placemark->get_id());
|
||||
|
||||
// Serialize the sample.
|
||||
std::string parsed_kml = kmldom::SerializePretty(placemark);
|
||||
cout << parsed_kml << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
CheckId();
|
||||
CheckHotSpot();
|
||||
return 0; // All is well if we got this far.
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// An example of coding from/to parse/serialize of enumerations.
|
||||
// For example <altitudeMode>absolute</altitudeMode>.
|
||||
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
|
||||
using kmldom::ElementPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::LinkPtr;
|
||||
using kmldom::LookAtPtr;
|
||||
|
||||
// Parse KML with enum and verify through the DOM API.
|
||||
void CheckParseLookAt() {
|
||||
// Parse some KML with an enum
|
||||
std::string kml("<LookAt><altitudeMode>absolute</altitudeMode></LookAt>");
|
||||
ElementPtr root = kmldom::Parse(kml, NULL);
|
||||
|
||||
// Verify the parse went fine.
|
||||
assert(root); // The kml is perfect.
|
||||
|
||||
// Verify the root is <LookAt>
|
||||
const LookAtPtr lookat = kmldom::AsLookAt(root);
|
||||
assert(lookat);
|
||||
|
||||
// Verify the altitudeMode exists and is correct.
|
||||
assert(lookat->has_altitudemode());
|
||||
assert(kmldom::ALTITUDEMODE_ABSOLUTE == lookat->get_altitudemode());
|
||||
}
|
||||
|
||||
void CheckParseLink() {
|
||||
// Parse a Link. These are non-default values.
|
||||
std::string kml("<Link>"
|
||||
"<href>foo.kml</href>"
|
||||
"<refreshMode>onInterval</refreshMode>"
|
||||
"<viewRefreshMode>onStop</viewRefreshMode>"
|
||||
"</Link>");
|
||||
ElementPtr root = kmldom::Parse(kml, NULL); // No error string because...
|
||||
assert(root); // ...we expect a perfect parse.
|
||||
|
||||
// Verify some things.
|
||||
const LinkPtr link = kmldom::AsLink(root);
|
||||
assert(true == link->has_refreshmode());
|
||||
assert(kmldom::REFRESHMODE_ONINTERVAL == link->get_refreshmode());
|
||||
assert(true == link->has_viewrefreshmode());
|
||||
assert(kmldom::VIEWREFRESHMODE_ONSTOP == link->get_viewrefreshmode());
|
||||
}
|
||||
|
||||
// Create KML with the DOM API, serialize and verify the output.
|
||||
void CheckSerializeLookAt() {
|
||||
// Create a LookAt and set its altitudeMode
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
LookAtPtr lookat = factory->CreateLookAt();
|
||||
lookat->set_altitudemode(kmldom::ALTITUDEMODE_RELATIVETOGROUND);
|
||||
|
||||
// Read back altitudeMode with the DOM API.
|
||||
assert(lookat->has_altitudemode());
|
||||
assert(kmldom::ALTITUDEMODE_RELATIVETOGROUND == lookat->get_altitudemode());
|
||||
|
||||
// Serialize it out to a string
|
||||
std::string kml = kmldom::SerializePretty(lookat);
|
||||
std::cout << kml << std::endl;
|
||||
// <LookAt>
|
||||
// <altitudeMode>relativeToGround</altitudeMode>
|
||||
// </LookAt>
|
||||
|
||||
// Verify the string is correct. (SerializePretty() adds 2 space indent).
|
||||
assert(kml.find("<LookAt>") == 0);
|
||||
assert(kml.find("<altitudeMode>") == 11);
|
||||
assert(kml.find("relativeToGround") == 25);
|
||||
assert(kml.find("</altitudeMode>") == 41);
|
||||
assert(kml.find("</LookAt>") == 57);
|
||||
}
|
||||
|
||||
void CheckLinkFactory() {
|
||||
// Create a <Link/>.
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
LinkPtr link = factory->CreateLink();
|
||||
|
||||
// Verify defaults.
|
||||
assert(false == link->has_refreshmode());
|
||||
assert(kmldom::REFRESHMODE_ONCHANGE == link->get_refreshmode());
|
||||
assert(false == link->has_viewrefreshmode());
|
||||
assert(kmldom::VIEWREFRESHMODE_NEVER == link->get_viewrefreshmode());
|
||||
|
||||
// Change a few things.
|
||||
const char kGooKml[] = "goo.kml";
|
||||
link->set_href(kGooKml);
|
||||
link->set_refreshmode(kmldom::REFRESHMODE_ONEXPIRE);
|
||||
link->set_viewrefreshmode(kmldom::VIEWREFRESHMODE_ONREGION);
|
||||
|
||||
// Serialize and verify elements have changed:
|
||||
std::string changed_kml = kmldom::SerializePretty(link);
|
||||
std::cout << changed_kml << std::endl;
|
||||
|
||||
// <Link>
|
||||
// <href>goo.kml</href>
|
||||
// <refreshMode>onExpire</refreshMode>
|
||||
// <viewRefreshMode>onRegion</viewRefreshMode>
|
||||
// </Link>
|
||||
|
||||
assert(0 == changed_kml.find("<Link>"));
|
||||
assert(9 == changed_kml.find("<href>"));
|
||||
assert(15 == changed_kml.find(kGooKml));
|
||||
assert(22 == changed_kml.find("</href>"));
|
||||
assert(32 == changed_kml.find("<refreshMode>"));
|
||||
assert(45 == changed_kml.find("onExpire"));
|
||||
assert(53 == changed_kml.find("</refreshMode>"));
|
||||
assert(70 == changed_kml.find("<viewRefreshMode>"));
|
||||
assert(87 == changed_kml.find("onRegion"));
|
||||
assert(95 == changed_kml.find("</viewRefreshMode>"));
|
||||
assert(114 == changed_kml.find("</Link>"));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
CheckParseLookAt();
|
||||
CheckParseLink();
|
||||
CheckSerializeLookAt();
|
||||
CheckLinkFactory();
|
||||
return 0; // All is well if we got this far.
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Walks the container hierarchy of the KML file printing about each Feature.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/base/file.h"
|
||||
#include "print.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using kmldom::ElementPtr;
|
||||
using kmldom::FeaturePtr;
|
||||
using kmldom::KmlPtr;
|
||||
|
||||
static const FeaturePtr GetRootFeature(const ElementPtr& root) {
|
||||
const KmlPtr kml = kmldom::AsKml(root);
|
||||
if (kml && kml->has_feature()) {
|
||||
return kml->get_feature();
|
||||
}
|
||||
return kmldom::AsFeature(root);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cout << "usage: " << argv[0] << " kmlfile" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read it.
|
||||
std::string kml;
|
||||
if (!kmlbase::File::ReadFileToString(argv[1], &kml)) {
|
||||
cout << argv[1] << " read failed" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse it.
|
||||
std::string errors;
|
||||
ElementPtr root = kmldom::Parse(kml, &errors);
|
||||
if (!root) {
|
||||
cout << errors;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Print it.
|
||||
const FeaturePtr feature = GetRootFeature(root);
|
||||
if (feature) {
|
||||
PrintFeature(feature, 0);
|
||||
} else {
|
||||
cout << "No root feature" << endl;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
using kmldom::CoordinatesPtr;
|
||||
using kmldom::FeaturePtr;
|
||||
using kmldom::FolderPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmldom::PointPtr;
|
||||
|
||||
PlacemarkPtr CreatePlacemark(kmldom::KmlFactory* factory,
|
||||
const string& name,
|
||||
double lat, double lng) {
|
||||
PlacemarkPtr placemark(factory->CreatePlacemark());
|
||||
placemark->set_name(name);
|
||||
|
||||
CoordinatesPtr coordinates(factory->CreateCoordinates());
|
||||
coordinates->add_latlng(lat, lng);
|
||||
|
||||
PointPtr point(factory->CreatePoint());
|
||||
point->set_coordinates(coordinates);
|
||||
|
||||
placemark->set_geometry(point);
|
||||
|
||||
return placemark;
|
||||
}
|
||||
|
||||
static const unsigned int kHowManyPoints = 1001;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
KmlFactory* factory(KmlFactory::GetFactory());
|
||||
|
||||
// Create a Folder, fill it with Placemarks.
|
||||
cout << "Creating " << kHowManyPoints << " Placemarks:" << endl;
|
||||
FolderPtr folder = factory->CreateFolder();
|
||||
for (size_t i = 0 ; i < kHowManyPoints ; ++i) {
|
||||
folder->add_feature(CreatePlacemark(factory, "hi", 1.1, 2.2));
|
||||
}
|
||||
|
||||
// Read back all the Placemarks in the Folder.
|
||||
cout << "Iterating " << kHowManyPoints << " Placemarks:" << endl;
|
||||
assert(kHowManyPoints == folder->get_feature_array_size());
|
||||
for (size_t i = 0; i < folder->get_feature_array_size(); ++i) {
|
||||
assert("hi" == folder->get_feature_array_at(i)->get_name());
|
||||
assert(kmldom::Type_Placemark == folder->get_feature_array_at(i)->Type());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,235 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file contains some sample code for Geometry elements:
|
||||
// Point, LineString, LinearRing, Polygon, MultiGeometry
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "kml/dom.h"
|
||||
|
||||
using std::stringstream;
|
||||
using kmldom::CoordinatesPtr;
|
||||
using kmldom::FolderPtr;
|
||||
using kmldom::InnerBoundaryIsPtr;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::LinearRingPtr;
|
||||
using kmldom::LineStringPtr;
|
||||
using kmldom::MultiGeometryPtr;
|
||||
using kmldom::OuterBoundaryIsPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmldom::PointPtr;
|
||||
using kmldom::PolygonPtr;
|
||||
|
||||
static void CreateGeometry(bool verbose);
|
||||
template<int N> static LinearRingPtr CreateBoundary(const double (&corners)[N]);
|
||||
static PlacemarkPtr CreateLineStringPlacemark();
|
||||
static PlacemarkPtr CreateMultiGeometryPlacemark();
|
||||
static PointPtr Create2dPoint(int id, double longitude, double latitude);
|
||||
static PlacemarkPtr CreatePointPlacemark();
|
||||
static PlacemarkPtr CreateSimplePolygon();
|
||||
static PlacemarkPtr CreateTwoHolePolygon();
|
||||
|
||||
static PlacemarkPtr CreatePointPlacemark() {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
|
||||
CoordinatesPtr coordinates = factory->CreateCoordinates();
|
||||
coordinates->add_latlng(36.36, -123.32);
|
||||
|
||||
PointPtr point = factory->CreatePoint();
|
||||
point->set_coordinates(coordinates);
|
||||
|
||||
PlacemarkPtr placemark = factory->CreatePlacemark();
|
||||
placemark->set_name("Point");
|
||||
placemark->set_geometry(point);
|
||||
|
||||
return placemark;
|
||||
}
|
||||
|
||||
static PlacemarkPtr CreateLineStringPlacemark() {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
|
||||
CoordinatesPtr coordinates = factory->CreateCoordinates();
|
||||
coordinates->add_latlngalt(38.38, -121.12, 123.456);
|
||||
coordinates->add_latlngalt(37.37, -122.22, 122.345);
|
||||
coordinates->add_latlngalt(36.36, -123.32, 121.234);
|
||||
coordinates->add_latlng(36.36, -123.32);
|
||||
|
||||
LineStringPtr linestring = factory->CreateLineString();
|
||||
linestring->set_extrude(true);
|
||||
linestring->set_tessellate(true);
|
||||
linestring->set_altitudemode(kmldom::ALTITUDEMODE_ABSOLUTE);
|
||||
linestring->set_coordinates(coordinates);
|
||||
|
||||
PlacemarkPtr placemark = factory->CreatePlacemark();
|
||||
placemark->set_geometry(linestring);
|
||||
placemark->set_name("LineString");
|
||||
|
||||
return placemark;
|
||||
}
|
||||
|
||||
static PlacemarkPtr CreateSimplePolygon() {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
|
||||
CoordinatesPtr coordinates = factory->CreateCoordinates();
|
||||
coordinates->add_latlngalt(38.38, -121.12, 123.456);
|
||||
coordinates->add_latlngalt(37.37, -122.22, 122.345);
|
||||
coordinates->add_latlngalt(36.36, -123.32, 121.234);
|
||||
coordinates->add_latlngalt(38.38, -121.12, 123.456);
|
||||
|
||||
LinearRingPtr linearring = factory->CreateLinearRing();
|
||||
linearring->set_coordinates(coordinates);
|
||||
|
||||
OuterBoundaryIsPtr outerboundaryis = factory->CreateOuterBoundaryIs();
|
||||
outerboundaryis->set_linearring(linearring);
|
||||
|
||||
PolygonPtr polygon = factory->CreatePolygon();
|
||||
polygon->set_tessellate(true);
|
||||
polygon->set_altitudemode(kmldom::ALTITUDEMODE_RELATIVETOGROUND);
|
||||
polygon->set_outerboundaryis(outerboundaryis);
|
||||
|
||||
PlacemarkPtr placemark = factory->CreatePlacemark();
|
||||
placemark->set_name("Simple Polygon");
|
||||
placemark->set_geometry(polygon);
|
||||
|
||||
return placemark;
|
||||
}
|
||||
|
||||
// Corners presumed to be the corners of the ring.
|
||||
template<int N>
|
||||
static LinearRingPtr CreateBoundary(const double (&corners)[N]) {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
CoordinatesPtr coordinates = factory->CreateCoordinates();
|
||||
for (int i = 0; i < N; i+=2) {
|
||||
coordinates->add_latlng(corners[i], corners[i+1]);
|
||||
}
|
||||
// Last must be the same as first in a LinearRing.
|
||||
coordinates->add_latlng(corners[0], corners[1]);
|
||||
|
||||
LinearRingPtr linearring = factory->CreateLinearRing();
|
||||
linearring->set_coordinates(coordinates);
|
||||
return linearring;
|
||||
}
|
||||
|
||||
static PlacemarkPtr CreateTwoHolePolygon() {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
PlacemarkPtr placemark = factory->CreatePlacemark();
|
||||
placemark->set_name("Polygon with 2 holes");
|
||||
|
||||
PolygonPtr polygon = factory->CreatePolygon();
|
||||
|
||||
const double outer_corners[] = {
|
||||
37.80198570954779,-122.4319382787491,
|
||||
37.80166118304026,-122.4318730681021,
|
||||
37.8017138829201,-122.4314979385389,
|
||||
37.80202995372478,-122.4315644851293
|
||||
};
|
||||
|
||||
const double inner_west_corners[] = {
|
||||
37.80193182195953,-122.4318860160652,
|
||||
37.80172085332186,-122.4318421173957,
|
||||
37.80173660441158,-122.4317194993788,
|
||||
37.8019475540673,-122.4317632243884
|
||||
};
|
||||
|
||||
const double inner_east_corners[] = {
|
||||
37.80195363606838,-122.4317133795781,
|
||||
37.80174288373532,-122.4316718851426,
|
||||
37.8017586463012,-122.4315492963515,
|
||||
37.80196848593953,-122.4315926416269
|
||||
};
|
||||
OuterBoundaryIsPtr outerboundaryis = factory->CreateOuterBoundaryIs();
|
||||
outerboundaryis->set_linearring(CreateBoundary(outer_corners));
|
||||
polygon->set_outerboundaryis(outerboundaryis);
|
||||
|
||||
InnerBoundaryIsPtr innerboundaryis = factory->CreateInnerBoundaryIs();
|
||||
innerboundaryis->set_linearring(CreateBoundary(inner_west_corners));
|
||||
polygon->add_innerboundaryis(innerboundaryis);
|
||||
|
||||
innerboundaryis = factory->CreateInnerBoundaryIs();
|
||||
innerboundaryis->set_linearring(CreateBoundary(inner_east_corners));
|
||||
polygon->add_innerboundaryis(innerboundaryis);
|
||||
|
||||
placemark->set_geometry(polygon);
|
||||
|
||||
return placemark;
|
||||
}
|
||||
|
||||
static PointPtr Create2dPoint(int id, double longitude, double latitude) {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
|
||||
CoordinatesPtr coordinates = factory->CreateCoordinates();
|
||||
coordinates->add_latlng(longitude, latitude);
|
||||
|
||||
PointPtr point = factory->CreatePoint();
|
||||
stringstream ss;
|
||||
ss << "pt_" << id;
|
||||
point->set_id(ss.str());
|
||||
point->set_coordinates(coordinates);
|
||||
return point;
|
||||
}
|
||||
|
||||
static PlacemarkPtr CreateMultiGeometryPlacemark() {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
|
||||
PlacemarkPtr placemark = factory->CreatePlacemark();
|
||||
placemark->set_name("MultiGeometry");
|
||||
placemark->set_id("pmmg");
|
||||
MultiGeometryPtr multigeometry = factory->CreateMultiGeometry();
|
||||
placemark->set_geometry(multigeometry);
|
||||
|
||||
const int num_points = 3;
|
||||
for (int i = 0; i < num_points; ++i) {
|
||||
multigeometry->add_geometry(Create2dPoint(-120 + i, i, 37 + i));
|
||||
}
|
||||
|
||||
return placemark;
|
||||
}
|
||||
|
||||
static void CreateGeometry(bool verbose) {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
|
||||
FolderPtr folder = factory->CreateFolder();
|
||||
folder->add_feature(CreatePointPlacemark());
|
||||
folder->add_feature(CreateLineStringPlacemark());
|
||||
folder->add_feature(CreateSimplePolygon());
|
||||
folder->add_feature(CreateTwoHolePolygon());
|
||||
folder->add_feature(CreateMultiGeometryPlacemark());
|
||||
|
||||
KmlPtr kml = factory->CreateKml();
|
||||
kml->set_feature(folder);
|
||||
|
||||
if (verbose) {
|
||||
std::cout << kmldom::SerializePretty(kml);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// Silent by default.
|
||||
bool verbose = argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v';
|
||||
CreateGeometry(verbose);
|
||||
return 0; // All is well if we got this far.
|
||||
}
|
|
@ -0,0 +1,220 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program prints the hrefs in the supplied KML file.
|
||||
// The following elements have hrefs:
|
||||
// NetworkLink/Link or Url
|
||||
// Overlay/Icon
|
||||
// Model/Link
|
||||
// IconStyle/Icon
|
||||
// ItemIcon/href
|
||||
// These are also "hrefs", but are not printed by this program:
|
||||
// styleUrl, schemaUrl, targetHref, sourceHref
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/base/file.h"
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using kmldom::BasicLinkPtr;
|
||||
using kmldom::ContainerPtr;
|
||||
using kmldom::DocumentPtr;
|
||||
using kmldom::ElementPtr;
|
||||
using kmldom::FeaturePtr;
|
||||
using kmldom::GeometryPtr;
|
||||
using kmldom::IconStylePtr;
|
||||
using kmldom::ItemIconPtr;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::ListStylePtr;
|
||||
using kmldom::ModelPtr;
|
||||
using kmldom::MultiGeometryPtr;
|
||||
using kmldom::NetworkLinkPtr;
|
||||
using kmldom::OverlayPtr;
|
||||
using kmldom::PairPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmldom::StylePtr;
|
||||
using kmldom::StyleMapPtr;
|
||||
using kmldom::StyleSelectorPtr;
|
||||
|
||||
// Declare all functions used here.
|
||||
static const FeaturePtr GetRootFeature(const ElementPtr& root);
|
||||
static void PrintBasicLinkHref(const string what, const BasicLinkPtr& link);
|
||||
static void PrintIconStyleIconHref(const IconStylePtr& iconstyle);
|
||||
static void PrintModelLinkHref(const ModelPtr& model);
|
||||
static void PrintNetworkLinkHref(const NetworkLinkPtr& networklink);
|
||||
static void PrintOverlayIconHref(const OverlayPtr& overlay);
|
||||
static void VisitContainer(const ContainerPtr& container);
|
||||
static void VisitFeature(const FeaturePtr& feature);
|
||||
static void VisitFeatureStyle(const FeaturePtr& feature);
|
||||
static void VisitGeometry(const GeometryPtr& geometry);
|
||||
static void VisitListStyle(const ListStylePtr& liststyle);
|
||||
static void VisitPlacemark(const PlacemarkPtr& placemark);
|
||||
static void VisitStyle(const StylePtr& style);
|
||||
static void VisitStyleMap(const StyleMapPtr& stylemap);
|
||||
static void VisitStyleSelector(const StyleSelectorPtr& styleselector);
|
||||
|
||||
static const FeaturePtr GetRootFeature(const ElementPtr& root) {
|
||||
const KmlPtr kml = kmldom::AsKml(root);
|
||||
if (kml && kml->has_feature()) {
|
||||
return kml->get_feature();
|
||||
}
|
||||
return kmldom::AsFeature(root);
|
||||
}
|
||||
|
||||
// Link, Icon, Url are all BasicLink
|
||||
static void PrintBasicLinkHref(const string what, const BasicLinkPtr& link) {
|
||||
if (link) {
|
||||
cout << what << " " << link->get_href() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintNetworkLinkHref(const NetworkLinkPtr& networklink) {
|
||||
PrintBasicLinkHref("NetworkLink", networklink->get_link());
|
||||
}
|
||||
|
||||
static void PrintOverlayIconHref(const OverlayPtr& overlay) {
|
||||
PrintBasicLinkHref("Overlay", overlay->get_icon());
|
||||
}
|
||||
|
||||
static void PrintIconStyleIconHref(const IconStylePtr& iconstyle) {
|
||||
PrintBasicLinkHref("IconStyle", iconstyle->get_icon());
|
||||
}
|
||||
|
||||
static void PrintModelLinkHref(const ModelPtr& model) {
|
||||
PrintBasicLinkHref("Model", model->get_link());
|
||||
}
|
||||
|
||||
static void VisitGeometry(const GeometryPtr& geometry) {
|
||||
const MultiGeometryPtr multigeometry = kmldom::AsMultiGeometry(geometry);
|
||||
if (multigeometry) {
|
||||
for (size_t i = 0; i < multigeometry->get_geometry_array_size(); ++i) {
|
||||
VisitGeometry(multigeometry->get_geometry_array_at(i));
|
||||
}
|
||||
} else if (const ModelPtr model = kmldom::AsModel(geometry)) {
|
||||
PrintModelLinkHref(model);
|
||||
}
|
||||
}
|
||||
|
||||
static void VisitPlacemark(const PlacemarkPtr& placemark) {
|
||||
if (placemark->has_geometry()) {
|
||||
VisitGeometry(placemark->get_geometry());
|
||||
}
|
||||
}
|
||||
|
||||
static void VisitListStyle(const ListStylePtr& liststyle) {
|
||||
for (size_t i = 0; i < liststyle->get_itemicon_array_size(); ++i) {
|
||||
// ItemIcon is not a BasicLink.
|
||||
if (liststyle->get_itemicon_array_at(i)->has_href()) {
|
||||
cout << "ItemIcon " << liststyle->get_itemicon_array_at(i)->get_href()
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void VisitStyle(const StylePtr& style) {
|
||||
if (style->has_iconstyle()) {
|
||||
PrintIconStyleIconHref(style->get_iconstyle());
|
||||
}
|
||||
if (style->has_liststyle()) {
|
||||
VisitListStyle(style->get_liststyle());
|
||||
}
|
||||
}
|
||||
|
||||
static void VisitStyleSelector(const StyleSelectorPtr& styleselector) {
|
||||
if (const StylePtr style = kmldom::AsStyle(styleselector)) { // for IconStyle
|
||||
VisitStyle(style);
|
||||
} else if (const StyleMapPtr stylemap = kmldom::AsStyleMap(styleselector)) {
|
||||
VisitStyleMap(stylemap);
|
||||
}
|
||||
}
|
||||
|
||||
static void VisitStyleMap(const StyleMapPtr& stylemap) {
|
||||
for (size_t i = 0; i < stylemap->get_pair_array_size(); ++i) {
|
||||
if (stylemap->get_pair_array_at(i)->has_styleselector()) {
|
||||
VisitStyleSelector(stylemap->get_pair_array_at(i)->get_styleselector());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void VisitFeatureStyle(const FeaturePtr& feature) {
|
||||
if (feature->has_styleselector()) {
|
||||
VisitStyleSelector(feature->get_styleselector());
|
||||
}
|
||||
// visit list if Document
|
||||
if (const DocumentPtr document = kmldom::AsDocument(feature)) {
|
||||
for (size_t i = 0; i < document->get_styleselector_array_size(); ++i) {
|
||||
VisitStyleSelector(document->get_styleselector_array_at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void VisitContainer(const ContainerPtr& container) {
|
||||
for (size_t i = 0; i < container->get_feature_array_size(); ++i) {
|
||||
VisitFeature(container->get_feature_array_at(i));
|
||||
}
|
||||
}
|
||||
|
||||
static void VisitFeature(const FeaturePtr& feature) {
|
||||
VisitFeatureStyle(feature);
|
||||
if (const ContainerPtr container = kmldom::AsContainer(feature)) {
|
||||
VisitContainer(container);
|
||||
} else if (const NetworkLinkPtr networklink =
|
||||
kmldom::AsNetworkLink(feature)) {
|
||||
PrintNetworkLinkHref(networklink);
|
||||
} else if (const OverlayPtr overlay = kmldom::AsOverlay(feature)) {
|
||||
PrintOverlayIconHref(overlay);
|
||||
} else if (const PlacemarkPtr placemark = kmldom::AsPlacemark(feature)) {
|
||||
VisitPlacemark(placemark); // Model
|
||||
}
|
||||
}
|
||||
|
||||
static void HandleFile(const char* kmlfile) {
|
||||
cout << kmlfile << endl;
|
||||
string kml;
|
||||
bool status = kmlbase::File::ReadFileToString(kmlfile, &kml);
|
||||
if (!status) {
|
||||
return;
|
||||
}
|
||||
string errors;
|
||||
ElementPtr root = kmldom::Parse(kml, &errors);
|
||||
if (!root) {
|
||||
return;
|
||||
}
|
||||
if (const FeaturePtr feature = GetRootFeature(root)) {
|
||||
VisitFeature(feature);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cout << "usage: " << argv[0] << " file.kml" << endl;
|
||||
return 1;
|
||||
}
|
||||
const char* kmlfile = argv[1];
|
||||
HandleFile(kmlfile);
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// An example of the KMZ API, showing DataIsKmz() and ReadKmlFromKmz().
|
||||
// Prints the default KML file in a KMZ archive, if found, or the first KML
|
||||
// file.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/base/file.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using kmlengine::KmzFile;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cout << "usage: " << argv[0] << " kmzfile" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::scoped_ptr<KmzFile> kmz_file(KmzFile::OpenFromFile(argv[1]));
|
||||
if (!kmz_file) {
|
||||
cout << "error: " << argv[1] << " is not a valid kmz file" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string kml;
|
||||
if (!kmz_file->ReadKml(&kml)) {
|
||||
cout << "error: no data read from " << argv[1] << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << kml << endl;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program generates GroundOverlays with Regions. The two overlays have
|
||||
// exclusive Lods on their Regions, hence they swap as the viewpoint changes.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
|
||||
using kmldom::FolderPtr;
|
||||
using kmldom::GroundOverlayPtr;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::LatLonAltBoxPtr;
|
||||
using kmldom::LatLonBoxPtr;
|
||||
using kmldom::LodPtr;
|
||||
using kmldom::RegionPtr;
|
||||
|
||||
// Declare functions defined in this file.
|
||||
static GroundOverlayPtr CreateGroundOverlay(double north, double south,
|
||||
double east, double west,
|
||||
const std::string& name,
|
||||
const std::string& color);
|
||||
static RegionPtr CreateRegion(double north, double south,
|
||||
double east, double west,
|
||||
double minlodpixels, double maxlodpixels);
|
||||
void SwapOverlays();
|
||||
|
||||
// This creates a Region at the given bounding box with the given Lod range.
|
||||
static RegionPtr CreateRegion(double north, double south,
|
||||
double east, double west,
|
||||
double minlodpixels, double maxlodpixels) {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
RegionPtr region = factory->CreateRegion();
|
||||
LatLonAltBoxPtr latlonaltbox = factory->CreateLatLonAltBox();
|
||||
latlonaltbox->set_north(north);
|
||||
latlonaltbox->set_south(south);
|
||||
latlonaltbox->set_east(east);
|
||||
latlonaltbox->set_west(west);
|
||||
LodPtr lod = factory->CreateLod();
|
||||
lod->set_minlodpixels(minlodpixels);
|
||||
lod->set_maxlodpixels(maxlodpixels);
|
||||
region->set_latlonaltbox(latlonaltbox);
|
||||
region->set_lod(lod);
|
||||
return region;
|
||||
}
|
||||
|
||||
// This creates a GroundOverlay at the given bounding box.
|
||||
// Since there is no Icon (image) a polygon of the given color is drawn.
|
||||
static GroundOverlayPtr CreateGroundOverlay(double north, double south,
|
||||
double east, double west,
|
||||
const std::string& name,
|
||||
const std::string& color) {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
GroundOverlayPtr groundoverlay = factory->CreateGroundOverlay();
|
||||
groundoverlay->set_name(name);
|
||||
LatLonBoxPtr latlonbox = factory->CreateLatLonBox();
|
||||
latlonbox->set_north(north);
|
||||
latlonbox->set_south(south);
|
||||
latlonbox->set_east(east);
|
||||
latlonbox->set_west(west);
|
||||
groundoverlay->set_latlonbox(latlonbox);
|
||||
groundoverlay->set_color(color);
|
||||
return groundoverlay;
|
||||
}
|
||||
|
||||
// This uses Regions to make a clean swap between overlays.
|
||||
// Set minLodPixels of one Region to the same as maxLodPixels of the other.
|
||||
void SwapOverlays() {
|
||||
KmlFactory* factory = KmlFactory::GetFactory();
|
||||
double north = 10;
|
||||
double south = -10;
|
||||
double east = 10;
|
||||
double west = -10;
|
||||
double lod_a = 128; // 128 x 128 pixels
|
||||
double lod_b = 512;
|
||||
double lod_c = 1024;
|
||||
std::string solid_red("ff0000ff"); // aabbggrr
|
||||
std::string solid_blue("ffff0000");
|
||||
|
||||
// Create a solid red GroundOverlay.
|
||||
GroundOverlayPtr red =
|
||||
CreateGroundOverlay(north, south, east, west, "Red", solid_red);
|
||||
// Give it a Region with lod range a - b
|
||||
red->set_region(CreateRegion(north, south, east, west, lod_a, lod_b));
|
||||
// Create a solid blue GroundOverlay.
|
||||
GroundOverlayPtr blue =
|
||||
CreateGroundOverlay(north, south, east, west, "Blue", solid_blue);
|
||||
// Give it a Region with lod range b - c
|
||||
blue->set_region(CreateRegion(north, south, east, west, lod_b, lod_c));
|
||||
|
||||
FolderPtr folder = factory->CreateFolder();
|
||||
folder->set_name("Swap Overlays");
|
||||
folder->add_feature(red);
|
||||
folder->add_feature(blue);
|
||||
|
||||
KmlPtr kml = factory->CreateKml();
|
||||
kml->set_feature(folder);
|
||||
|
||||
std::cout << kmldom::SerializePretty(kml);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
SwapOverlays();
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program makes some basic use of the KML DOM API.
|
||||
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include "kml/dom.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using kmldom::CoordinatesPtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmldom::PointPtr;
|
||||
|
||||
void HelloKml(bool verbose) {
|
||||
KmlFactory* factory(KmlFactory::GetFactory());
|
||||
// <coordinates>
|
||||
CoordinatesPtr coordinates(factory->CreateCoordinates());
|
||||
coordinates->add_latlngalt(37.123, -122.456, 314.159);
|
||||
// <Point><coordinates>...
|
||||
PointPtr point(factory->CreatePoint());
|
||||
point->set_coordinates(coordinates);
|
||||
// <Point><altitudeMode>...<coordinates>...
|
||||
point->set_altitudemode(kmldom::ALTITUDEMODE_RELATIVETOGROUND);
|
||||
assert(point->get_altitudemode() == kmldom::ALTITUDEMODE_RELATIVETOGROUND);
|
||||
// <Placemark><Point><coordinates>...
|
||||
PlacemarkPtr placemark(factory->CreatePlacemark());
|
||||
placemark->set_geometry(point);
|
||||
|
||||
// A Placemark is (duh) a Placemark
|
||||
assert (placemark->Type() == kmldom::Type_Placemark);
|
||||
// It's also a Feature.
|
||||
assert(placemark->IsA(kmldom::Type_Feature));
|
||||
placemark->set_name("point placemark");
|
||||
if (verbose) {
|
||||
cout << "Placemark's name is " << placemark->get_name() << endl;
|
||||
}
|
||||
// We know it has some geometry.
|
||||
assert(placemark->has_geometry());
|
||||
// And we can test to see if that geometry is a Point.
|
||||
assert(placemark->get_geometry()->IsA(kmldom::Type_Point));
|
||||
// If it is, we can make a point from it. (Yes, API should hide casting.)
|
||||
const PointPtr pt = kmldom::AsPoint(placemark->get_geometry());
|
||||
assert(pt->get_altitudemode() == kmldom::ALTITUDEMODE_RELATIVETOGROUND);
|
||||
if (verbose) {
|
||||
cout.precision(6);
|
||||
cout << placemark->get_name() << " is located at: ";
|
||||
cout << pt->get_coordinates()->get_coordinates_array_at(0).get_latitude()
|
||||
<< ", ";
|
||||
cout << pt->get_coordinates()->get_coordinates_array_at(0).get_longitude()
|
||||
<< endl;
|
||||
}
|
||||
|
||||
// All storage is freed by smart pointers as they go out of scope.
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
HelloKml(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v');
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This program shows basic usage of the buffered parsing method of the
|
||||
// kmlbase::ExpatParser class. By default it parses 1000000 placemarks. You
|
||||
// can override this by passing in a different number:
|
||||
// ./examples/helloworld/parsebuf 100
|
||||
//
|
||||
// For reference, on a 2.4 GHz Core2Duo MacBook Pro it takes around 2 seconds
|
||||
// to parse one million placemark elements:
|
||||
//
|
||||
// $ time ./examples/helloworld/parsebuf 1000000
|
||||
// real 0m2.046s
|
||||
// user 0m1.825s
|
||||
// sys 0m0.205s
|
||||
//
|
||||
// Five million placemarks takes roughly 10.5 seconds:
|
||||
// $ time ./examples/helloworld/parsebuf 5000000
|
||||
// real 0m10.416s
|
||||
// user 0m9.334s
|
||||
// sys 0m1.005s
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/base/expat_parser.h"
|
||||
#include "kml/dom/kml_handler.h"
|
||||
#include "kml/dom/parser_observer.h"
|
||||
#include "kml/dom.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
// The creation of an empty ParserObserver vector is necessary to
|
||||
// satisfy the current API.
|
||||
kmldom::parser_observer_vector_t observers;
|
||||
kmldom::KmlHandler kml_handler(observers);
|
||||
|
||||
kmlbase::ExpatParser parser(&kml_handler, false);
|
||||
|
||||
bool status = false;
|
||||
std::string errors;
|
||||
|
||||
// The content need not be split on element boundaries:
|
||||
parser.ParseBuffer("<k", NULL, false);
|
||||
parser.ParseBuffer("ml><Docume", NULL, false);
|
||||
parser.ParseBuffer("nt>", NULL, false);
|
||||
|
||||
// Parse one million placemarks, or the number specified on the cmd line.
|
||||
int count = 1000000;
|
||||
if (argc == 2) {
|
||||
count = atoi(argv[1]);
|
||||
}
|
||||
while (--count) {
|
||||
status = parser.ParseBuffer("<Placemark/>", &errors, false);
|
||||
if (!status) {
|
||||
std::cerr << "Parse failed: " << errors << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
status = parser.ParseBuffer("</Document></kml>", NULL, true);
|
||||
// A real client program would check the status here. In this contrived
|
||||
// example we know it succeeds.
|
||||
std::cout << "done" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// parsekml.cc
|
||||
// This program parses a KML Placemark from a memory buffer and prints
|
||||
// the value of the <name> element on standard output.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/dom.h" // The KML DOM header.
|
||||
|
||||
int main() {
|
||||
// Parse KML from a memory buffer.
|
||||
std::string errors;
|
||||
kmldom::ElementPtr element = kmldom::Parse(
|
||||
"<Placemark><name>hi</name></Placemark>",
|
||||
&errors);
|
||||
|
||||
// Convert the type of the root element of the parse.
|
||||
const kmldom::PlacemarkPtr placemark = kmldom::AsPlacemark(element);
|
||||
|
||||
// Access the value of the element.
|
||||
std::cout << "The Placemark name is: " << placemark->get_name()
|
||||
<< std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,207 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="parsekml"
|
||||
ProjectGUID="{5ADB0151-CD72-4260-9A4A-5C2FA7D53F72}"
|
||||
RootNamespace="parsekml"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\third_party\boost_1_34_1;..\..\src"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="libkmlbase.lib libkmldom.lib libexpat.lib"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="C:\Program Files\Expat 2.0.1\Bin;..\..\debug"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\third_party\boost_1_34_1;..\..\src"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="libkmlbase.lib libkmldom.lib libexpat.lib"
|
||||
AdditionalLibraryDirectories="C:\Program Files\Expat 2.0.1\Bin;..\..\release"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath="parsekml.cc"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This example shows basic usage of the namespace-aware parser.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/dom/kml_handler_ns.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/base/file.h"
|
||||
|
||||
using kmldom::ElementPtr;
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cout << "usage: " << argv[0] << " kmlfile" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read the file content.
|
||||
std::string kml;
|
||||
if (!kmlbase::File::ReadFileToString(argv[1], &kml)) {
|
||||
cout << argv[1] << " read failed" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse it.
|
||||
std::string errors;
|
||||
ElementPtr root = kmldom::ParseNS(kml, &errors);
|
||||
if (!root) {
|
||||
cout << errors << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Serialize it and output to stdout.
|
||||
std::string output;
|
||||
cout << kmldom::SerializePretty(root) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This sample program reads and parses one KML or KMZ file and emits the
|
||||
// serialization to standard output. Since all recognized elements
|
||||
// are saved in the KML DOM with white space discarded and Serialize()
|
||||
// formats nicely this is overall a pretty printer.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
#include "kml/dom.h"
|
||||
#include "kml/engine.h"
|
||||
#include "kml/base/file.h"
|
||||
|
||||
using kmlengine::KmlFile;
|
||||
using kmlengine::KmlFilePtr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) {
|
||||
cout << "usage: " << argv[0] << " kmlfile" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read the file content.
|
||||
std::string file_data;
|
||||
if (!kmlbase::File::ReadFileToString(argv[1], &file_data)) {
|
||||
cout << argv[1] << " read failed" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse it.
|
||||
std::string errors;
|
||||
KmlFilePtr kml_file = KmlFile::CreateFromParse(file_data, &errors);
|
||||
if (!kml_file) {
|
||||
cout << errors;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Serialize it to stdout.
|
||||
kml_file->SerializeToOstream(&cout);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,225 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="prettykml"
|
||||
ProjectGUID="{FC3E952B-9781-4DE5-A26B-A2D1DC8F9646}"
|
||||
RootNamespace="prettykml"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\third_party\boost_1_34_1;..\..\src;..\..\third_party\uriparser-0.7.1\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="libkmlbase.lib libkmldom.lib libkmlengine.lib libexpat.lib minizip.lib zlib.lib"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="C:\Program Files\Expat 2.0.1\Bin;..\..\debug;..\..\third_party\zlib-1.2.3.win32\lib"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\third_party\boost_1_34_1;..\..\src;..\..\third_party\uriparser-0.7.1\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="libkmlbase.lib libkmldom.lib libkmlengine.lib libexpat.lib minizip.lib zlib.lib"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="C:\Program Files\Expat 2.0.1\Bin;..\..\release;..\..\third_party\zlib-1.2.3.win32\lib"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath="prettykml.cc"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
|
@ -0,0 +1,87 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "print.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
using kmldom::ContainerPtr;
|
||||
using kmldom::FeaturePtr;
|
||||
|
||||
void PrintIndented(string item, int depth) {
|
||||
while (depth--) {
|
||||
cout << " ";
|
||||
}
|
||||
cout << item;
|
||||
}
|
||||
|
||||
void PrintFeature(const FeaturePtr& feature, int depth) {
|
||||
switch (feature->Type()) {
|
||||
case kmldom::Type_Document:
|
||||
PrintIndented("Document", depth);
|
||||
break;
|
||||
case kmldom::Type_Folder:
|
||||
PrintIndented("Folder", depth);
|
||||
break;
|
||||
case kmldom::Type_GroundOverlay:
|
||||
PrintIndented("GroundOverlay", depth);
|
||||
break;
|
||||
case kmldom::Type_NetworkLink:
|
||||
PrintIndented("NetworkLink", depth);
|
||||
break;
|
||||
case kmldom::Type_PhotoOverlay:
|
||||
PrintIndented("PhotoOverlay", depth);
|
||||
break;
|
||||
case kmldom::Type_Placemark:
|
||||
PrintIndented("Placemark", depth);
|
||||
break;
|
||||
case kmldom::Type_ScreenOverlay:
|
||||
PrintIndented("ScreenOverlay", depth);
|
||||
break;
|
||||
default:
|
||||
PrintIndented("other", depth);
|
||||
break;
|
||||
}
|
||||
|
||||
if (feature->has_name()) {
|
||||
cout << " " << feature->get_name();
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
if (const ContainerPtr container = kmldom::AsContainer(feature)) {
|
||||
PrintContainer(container, depth+1);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintContainer(const ContainerPtr& container, int depth) {
|
||||
for (size_t i = 0; i < container->get_feature_array_size(); ++i) {
|
||||
PrintFeature(container->get_feature_array_at(i), depth);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Some KML printing utility functions.
|
||||
|
||||
#ifndef PRINT_H__
|
||||
#define PRINT_H__
|
||||
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
|
||||
// All PrintXXX() functions print to stdout.
|
||||
|
||||
// Print the given string indented according to depth.
|
||||
void PrintIndented(std::string item, int depth);
|
||||
|
||||
// Print each Feature in the container recursively.
|
||||
void PrintContainer(const kmldom::ContainerPtr& container, int depth);
|
||||
|
||||
// Print the name of the Feature. This recurses on Container.
|
||||
void PrintFeature(const kmldom::FeaturePtr& feature, int depth);
|
||||
|
||||
#endif // PRINT_H__
|
|
@ -0,0 +1,123 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Walks a Feature hierarchy, looking for Placemarks with Geometry, printing
|
||||
// the type of Geometry encountered.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/base/file.h"
|
||||
|
||||
using kmldom::ContainerPtr;
|
||||
using kmldom::ElementPtr;
|
||||
using kmldom::FeaturePtr;
|
||||
using kmldom::GeometryPtr;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::MultiGeometryPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
static void WalkGeometry(const GeometryPtr& geometry);
|
||||
static void WalkFeature(const FeaturePtr& feature);
|
||||
static void WalkContainer(const ContainerPtr& container);
|
||||
static const FeaturePtr GetRootFeature(const ElementPtr& root);
|
||||
|
||||
static void WalkGeometry(const GeometryPtr& geometry) {
|
||||
if (!geometry) {
|
||||
return;
|
||||
}
|
||||
// Print the Geometry type.
|
||||
cout << "Found a";
|
||||
switch(geometry->Type()) {
|
||||
case kmldom::Type_Point:
|
||||
cout << " Point";
|
||||
break;
|
||||
case kmldom::Type_LineString:
|
||||
cout << " LineString";
|
||||
break;
|
||||
case kmldom::Type_LinearRing:
|
||||
cout << " LinearRing";
|
||||
break;
|
||||
case kmldom::Type_Polygon:
|
||||
cout << " Polygon";
|
||||
break;
|
||||
case kmldom::Type_MultiGeometry:
|
||||
cout << " MultiGeometry";
|
||||
break;
|
||||
case kmldom::Type_Model:
|
||||
cout << " Model";
|
||||
break;
|
||||
default: // KML has 6 types of Geometry.
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
// Recurse into <MultiGeometry>.
|
||||
if (const MultiGeometryPtr multigeometry =
|
||||
kmldom::AsMultiGeometry(geometry)) {
|
||||
for (size_t i = 0; i < multigeometry->get_geometry_array_size(); ++i) {
|
||||
WalkGeometry(multigeometry->get_geometry_array_at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void WalkFeature(const FeaturePtr& feature) {
|
||||
if (feature) {
|
||||
if (const ContainerPtr container = kmldom::AsContainer(feature)) {
|
||||
WalkContainer(container);
|
||||
} else if (const PlacemarkPtr placemark = kmldom::AsPlacemark(feature)) {
|
||||
WalkGeometry(placemark->get_geometry());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void WalkContainer(const ContainerPtr& container) {
|
||||
for (size_t i = 0; i < container->get_feature_array_size(); ++i) {
|
||||
WalkFeature(container->get_feature_array_at(i));
|
||||
}
|
||||
}
|
||||
|
||||
static const FeaturePtr GetRootFeature(const ElementPtr& root) {
|
||||
const KmlPtr kml = kmldom::AsKml(root);
|
||||
if (kml && kml->has_feature()) {
|
||||
return kml->get_feature();
|
||||
}
|
||||
return kmldom::AsFeature(root);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string kml;
|
||||
kmlbase::File::ReadFileToString(argv[1], &kml);
|
||||
std::string errors;
|
||||
WalkFeature(GetRootFeature(kmldom::Parse(kml, &errors)));
|
||||
if (!errors.empty()) {
|
||||
cout << argv[1] << ": parse error" << endl;
|
||||
cout << errors << endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
// Copyright 2008, Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This sample program creates shared style selectors.
|
||||
|
||||
#include <iostream>
|
||||
#include "kml/dom.h"
|
||||
#include "kml/convenience/convenience.h"
|
||||
|
||||
using kmldom::DocumentPtr;
|
||||
using kmldom::IconStylePtr;
|
||||
using kmldom::KmlFactory;
|
||||
using kmldom::KmlPtr;
|
||||
using kmldom::PairPtr;
|
||||
using kmldom::PlacemarkPtr;
|
||||
using kmldom::StylePtr;
|
||||
using kmldom::StyleMapPtr;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
KmlFactory* kml_factory = KmlFactory::GetFactory();
|
||||
|
||||
DocumentPtr document = kml_factory->CreateDocument();
|
||||
|
||||
StylePtr normal = kml_factory->CreateStyle();
|
||||
normal->set_id("normal");
|
||||
IconStylePtr iconstyle = kml_factory->CreateIconStyle();
|
||||
iconstyle->set_scale(1.1);
|
||||
normal->set_iconstyle(iconstyle);
|
||||
document->add_styleselector(normal);
|
||||
|
||||
StylePtr highlight = kml_factory->CreateStyle();
|
||||
highlight->set_id("highlight");
|
||||
iconstyle = kml_factory->CreateIconStyle();
|
||||
iconstyle->set_scale(2.3);
|
||||
highlight->set_iconstyle(iconstyle);
|
||||
document->add_styleselector(highlight);
|
||||
|
||||
StyleMapPtr stylemap = kml_factory->CreateStyleMap();
|
||||
stylemap->set_id("stylemap");
|
||||
PairPtr pair = kml_factory->CreatePair();
|
||||
pair->set_key(kmldom::STYLESTATE_NORMAL);
|
||||
pair->set_styleurl("#normal");
|
||||
stylemap->add_pair(pair);
|
||||
|
||||
pair = kml_factory->CreatePair();
|
||||
pair->set_key(kmldom::STYLESTATE_HIGHLIGHT);
|
||||
pair->set_styleurl("#highlight");
|
||||
stylemap->add_pair(pair);
|
||||
|
||||
document->add_styleselector(stylemap);
|
||||
|
||||
PlacemarkPtr placemark =
|
||||
kmlconvenience::CreatePointPlacemark("Roll", 32.751645, -113.987817);
|
||||
placemark->set_styleurl("#stylemap");
|
||||
|
||||
document->add_feature(placemark);
|
||||
|
||||
KmlPtr kml = kml_factory->CreateKml();
|
||||
kml->set_feature(document);
|
||||
|
||||
std::cout << kmldom::SerializePretty(kml);
|
||||
|
||||
return 0;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue