[ogr-decode] source code format only.
This commit is contained in:
parent
6a00e62e08
commit
3e0ecec965
1 changed files with 363 additions and 365 deletions
|
@ -23,24 +23,24 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <string>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#include <ogrsf_frmts.h>
|
|
||||||
#include <gdal_priv.h>
|
#include <gdal_priv.h>
|
||||||
|
#include <ogrsf_frmts.h>
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
#include <simgear/threads/SGThread.hxx>
|
|
||||||
#include <simgear/threads/SGQueue.hxx>
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/math/sg_geodesy.hxx>
|
#include <simgear/math/sg_geodesy.hxx>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
#include <simgear/threads/SGQueue.hxx>
|
||||||
|
#include <simgear/threads/SGThread.hxx>
|
||||||
|
|
||||||
#include <Include/version.h>
|
#include <Include/version.h>
|
||||||
|
|
||||||
#include <terragear/tg_polygon.hxx>
|
|
||||||
#include <terragear/tg_chopper.hxx>
|
#include <terragear/tg_chopper.hxx>
|
||||||
|
#include <terragear/tg_polygon.hxx>
|
||||||
#include <terragear/tg_shapefile.hxx>
|
#include <terragear/tg_shapefile.hxx>
|
||||||
|
|
||||||
/* stretch endpoints to reduce slivers in linear data ~.1 meters */
|
/* stretch endpoints to reduce slivers in linear data ~.1 meters */
|
||||||
|
@ -74,22 +74,26 @@ const double gSnap = 0.00000001; // approx 1 mm
|
||||||
SGLockedQueue<OGRFeature*> global_workQueue;
|
SGLockedQueue<OGRFeature*> global_workQueue;
|
||||||
|
|
||||||
/* very GDAL specific here... */
|
/* very GDAL specific here... */
|
||||||
inline static bool is_ocean_area( const std::string &area ) {
|
inline static bool is_ocean_area(const std::string& area)
|
||||||
|
{
|
||||||
return area == "Ocean" || area == "Bay Estuary or Ocean";
|
return area == "Ocean" || area == "Bay Estuary or Ocean";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static bool is_void_area( const std::string &area ) {
|
inline static bool is_void_area(const std::string& area)
|
||||||
|
{
|
||||||
return area == "Void Area";
|
return area == "Void Area";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static bool is_null_area( const std::string& area ) {
|
inline static bool is_null_area(const std::string& area)
|
||||||
|
{
|
||||||
return area == "Null";
|
return area == "Null";
|
||||||
}
|
}
|
||||||
|
|
||||||
class Decoder : public SGThread
|
class Decoder : public SGThread {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Decoder( OGRCoordinateTransformation *poct, int atf, int pwf, int lwf, tgChopper& c ) : chopper(c) {
|
Decoder(OGRCoordinateTransformation* poct, int atf, int pwf, int lwf, tgChopper& c)
|
||||||
|
: chopper(c)
|
||||||
|
{
|
||||||
poCT = poct;
|
poCT = poct;
|
||||||
area_type_field = atf;
|
area_type_field = atf;
|
||||||
point_width_field = pwf;
|
point_width_field = pwf;
|
||||||
|
@ -160,24 +164,20 @@ void Decoder::processLineString(OGRLineString* poGeometry, const string& area_ty
|
||||||
p1 = SGGeod::fromDeg(poGeometry->getX(i), poGeometry->getY(i));
|
p1 = SGGeod::fromDeg(poGeometry->getX(i), poGeometry->getY(i));
|
||||||
SGGeodesy::inverse(p0, p1, heading, az2, dist);
|
SGGeodesy::inverse(p0, p1, heading, az2, dist);
|
||||||
|
|
||||||
if (dist > max_dist)
|
if (dist > max_dist) {
|
||||||
{
|
|
||||||
numSegs = (dist / max_dist) + 1;
|
numSegs = (dist / max_dist) + 1;
|
||||||
dist = dist / (double)numSegs;
|
dist = dist / (double)numSegs;
|
||||||
|
|
||||||
for (j=0; j<numSegs; j++)
|
for (j = 0; j < numSegs; j++) {
|
||||||
{
|
|
||||||
line.AddNode(SGGeodesy::direct(p0, heading, dist * (j + 1)));
|
line.AddNode(SGGeodesy::direct(p0, heading, dist * (j + 1)));
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
line.AddNode(p1);
|
line.AddNode(p1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// then stretch the last point
|
// then stretch the last point
|
||||||
// because vector data can generate adjacent polys, lets stretch the two enpoints by a little bit
|
// because vector data can generate adjacent polys, lets stretch the two endpoints by a little bit
|
||||||
p0 = SGGeod::fromDeg(poGeometry->getX(numPoints - 2), poGeometry->getY(numPoints - 2));
|
p0 = SGGeod::fromDeg(poGeometry->getX(numPoints - 2), poGeometry->getY(numPoints - 2));
|
||||||
p1 = SGGeod::fromDeg(poGeometry->getX(numPoints - 1), poGeometry->getY(numPoints - 1));
|
p1 = SGGeod::fromDeg(poGeometry->getX(numPoints - 1), poGeometry->getY(numPoints - 1));
|
||||||
|
|
||||||
|
@ -188,11 +188,13 @@ void Decoder::processLineString(OGRLineString* poGeometry, const string& area_ty
|
||||||
int texturing;
|
int texturing;
|
||||||
if (with_texture) {
|
if (with_texture) {
|
||||||
texturing = TG_TEX_BY_TPS_CLIPU;
|
texturing = TG_TEX_BY_TPS_CLIPU;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
texturing = TG_TEX_BY_GEODE;
|
texturing = TG_TEX_BY_GEODE;
|
||||||
}
|
}
|
||||||
if ( texture_cliffs ) texturing = TG_TEX_BY_HORIZ_REF;
|
|
||||||
|
if (texture_cliffs)
|
||||||
|
texturing = TG_TEX_BY_HORIZ_REF;
|
||||||
|
|
||||||
segments = tgContour::ExpandToPolygons(line, width, texturing);
|
segments = tgContour::ExpandToPolygons(line, width, texturing);
|
||||||
for (unsigned int i = 0; i < segments.size(); ++i) {
|
for (unsigned int i = 0; i < segments.size(); ++i) {
|
||||||
segments[i].SetPreserve3D(false);
|
segments[i].SetPreserve3D(false);
|
||||||
|
@ -238,9 +240,8 @@ void Decoder::run()
|
||||||
}
|
}
|
||||||
|
|
||||||
OGRwkbGeometryType geoType = wkbFlatten(poGeometry->getGeometryType());
|
OGRwkbGeometryType geoType = wkbFlatten(poGeometry->getGeometryType());
|
||||||
if (geoType!=wkbPoint && geoType!=wkbMultiPoint &&
|
if (geoType != wkbPoint && geoType != wkbMultiPoint && geoType != wkbLineString &&
|
||||||
geoType!=wkbLineString && geoType!=wkbMultiLineString &&
|
geoType != wkbMultiLineString && geoType != wkbPolygon && geoType != wkbMultiPolygon) {
|
||||||
geoType!=wkbPolygon && geoType!=wkbMultiPolygon) {
|
|
||||||
SG_LOG(SG_GENERAL, SG_INFO, "Unknown feature");
|
SG_LOG(SG_GENERAL, SG_INFO, "Unknown feature");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -330,7 +331,8 @@ void Decoder::run()
|
||||||
|
|
||||||
OGRMultiLineString* multilines = (OGRMultiLineString*)poGeometry;
|
OGRMultiLineString* multilines = (OGRMultiLineString*)poGeometry;
|
||||||
for (int i = 0; i < multilines->getNumGeometries(); ++i) {
|
for (int i = 0; i < multilines->getNumGeometries(); ++i) {
|
||||||
processLineString((OGRLineString*)(multilines->getGeometryRef(i)), area_type_name, width, texture_lines, texture_cliffs);
|
processLineString((OGRLineString*)(multilines->getGeometryRef(i)), area_type_name, width,
|
||||||
|
texture_lines, texture_cliffs);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -367,8 +369,7 @@ void processLayer(OGRLayer* poLayer, tgChopper& results )
|
||||||
if (!continue_on_errors) {
|
if (!continue_on_errors) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,8 +385,7 @@ void processLayer(OGRLayer* poLayer, tgChopper& results )
|
||||||
if (!continue_on_errors) {
|
if (!continue_on_errors) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,8 +397,7 @@ void processLayer(OGRLayer* poLayer, tgChopper& results )
|
||||||
if (!continue_on_errors) {
|
if (!continue_on_errors) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -410,8 +409,7 @@ void processLayer(OGRLayer* poLayer, tgChopper& results )
|
||||||
if (!continue_on_errors) {
|
if (!continue_on_errors) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,8 +422,7 @@ void processLayer(OGRLayer* poLayer, tgChopper& results )
|
||||||
if (!continue_on_errors) {
|
if (!continue_on_errors) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,8 +462,7 @@ void processLayer(OGRLayer* poLayer, tgChopper& results )
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Aborting!");
|
||||||
OCTDestroyCoordinateTransformation(poCT);
|
OCTDestroyCoordinateTransformation(poCT);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,8 +470,7 @@ void processLayer(OGRLayer* poLayer, tgChopper& results )
|
||||||
// Generate the work queue for this layer
|
// Generate the work queue for this layer
|
||||||
OGRFeature* poFeature;
|
OGRFeature* poFeature;
|
||||||
poLayer->SetNextByIndex(start_record);
|
poLayer->SetNextByIndex(start_record);
|
||||||
while ( ( poFeature = poLayer->GetNextFeature()) != NULL )
|
while ((poFeature = poLayer->GetNextFeature()) != NULL) {
|
||||||
{
|
|
||||||
global_workQueue.push(poFeature);
|
global_workQueue.push(poFeature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,9 +491,9 @@ void processLayer(OGRLayer* poLayer, tgChopper& results )
|
||||||
OCTDestroyCoordinateTransformation(poCT);
|
OCTDestroyCoordinateTransformation(poCT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(char* progname) {
|
void usage(char* progname)
|
||||||
SG_LOG( SG_GENERAL, SG_ALERT, "Usage: " <<
|
{
|
||||||
progname << " [options...] <work_dir> <datasource> [<layername>...]" );
|
SG_LOG(SG_GENERAL, SG_ALERT, "Usage: " << progname << " [options...] <work_dir> <datasource> [<layername>...]");
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Options:");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Options:");
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "--log-level priority");
|
SG_LOG(SG_GENERAL, SG_ALERT, "--log-level priority");
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, " Width in priority being bulk|debug|info|warn|alert");
|
SG_LOG(SG_GENERAL, SG_ALERT, " Width in priority being bulk|debug|info|warn|alert");
|
||||||
|
@ -543,15 +538,17 @@ void usage(char* progname) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "<layername>...");
|
SG_LOG(SG_GENERAL, SG_ALERT, "<layername>...");
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, " The layers to process.");
|
SG_LOG(SG_GENERAL, SG_ALERT, " The layers to process.");
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, " If no layer is given, all layers in the datasource are used");
|
SG_LOG(SG_GENERAL, SG_ALERT, " If no layer is given, all layers in the datasource are used");
|
||||||
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void setLoggingPriority(const char* p)
|
||||||
setLoggingPriority (const char * p)
|
|
||||||
{
|
{
|
||||||
if (p == 0)
|
if (p == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string priority = p;
|
string priority = p;
|
||||||
|
|
||||||
if (priority == "bulk") {
|
if (priority == "bulk") {
|
||||||
sglog().set_log_priority(SG_BULK);
|
sglog().set_log_priority(SG_BULK);
|
||||||
} else if (priority == "debug") {
|
} else if (priority == "debug") {
|
||||||
|
@ -567,7 +564,8 @@ setLoggingPriority (const char * p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char **argv ) {
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
char* progname = argv[0];
|
char* progname = argv[0];
|
||||||
string datasource, work_dir;
|
string datasource, work_dir;
|
||||||
|
|
||||||
|
@ -724,8 +722,7 @@ int main( int argc, char **argv ) {
|
||||||
GDALDataset* poDS;
|
GDALDataset* poDS;
|
||||||
|
|
||||||
poDS = (GDALDataset*)GDALOpenEx(datasource.c_str(), GDAL_OF_VECTOR, NULL, NULL, NULL);
|
poDS = (GDALDataset*)GDALOpenEx(datasource.c_str(), GDAL_OF_VECTOR, NULL, NULL, NULL);
|
||||||
if ( poDS == NULL )
|
if (poDS == NULL) {
|
||||||
{
|
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Failed opening datasource " << datasource);
|
SG_LOG(SG_GENERAL, SG_ALERT, "Failed opening datasource " << datasource);
|
||||||
|
|
||||||
GDALDestroyDriverManager();
|
GDALDestroyDriverManager();
|
||||||
|
@ -739,8 +736,7 @@ int main( int argc, char **argv ) {
|
||||||
if (argc > 3) {
|
if (argc > 3) {
|
||||||
for (int i = 3; i < argc; ++i) {
|
for (int i = 3; i < argc; ++i) {
|
||||||
poLayer = poDS->GetLayerByName(argv[i]);
|
poLayer = poDS->GetLayerByName(argv[i]);
|
||||||
if (poLayer == NULL )
|
if (poLayer == NULL) {
|
||||||
{
|
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Failed opening layer " << argv[i] << " from datasource " << datasource);
|
SG_LOG(SG_GENERAL, SG_ALERT, "Failed opening layer " << argv[i] << " from datasource " << datasource);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -765,7 +761,9 @@ int main( int argc, char **argv ) {
|
||||||
|
|
||||||
auto finish_time = std::chrono::high_resolution_clock::now();
|
auto finish_time = std::chrono::high_resolution_clock::now();
|
||||||
std::chrono::duration<double> elapsed = finish_time - start_time;
|
std::chrono::duration<double> elapsed = finish_time - start_time;
|
||||||
std::cout << std::endl << "Elapsed time: " << elapsed.count() << " seconds" << std::endl << std::endl;
|
std::cout << std::endl
|
||||||
|
<< "Elapsed time: " << elapsed.count() << " seconds" << std::endl
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue