Remove some warnings that MSVC complained about
This commit is contained in:
parent
9db8ec74f0
commit
858191ead9
4 changed files with 97 additions and 98 deletions
|
@ -36,13 +36,13 @@ static vector<AreaType> usgs_map;
|
||||||
|
|
||||||
int load_usgs_map( const std::string& filename ) {
|
int load_usgs_map( const std::string& filename ) {
|
||||||
ifstream in ( filename.c_str() );
|
ifstream in ( filename.c_str() );
|
||||||
|
|
||||||
if ( ! in ) {
|
if ( ! in ) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to open USGS map file " << filename);
|
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to open USGS map file " << filename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "USGS Map file is " << filename);
|
SG_LOG(SG_GENERAL, SG_ALERT, "USGS Map file is " << filename);
|
||||||
|
|
||||||
in >> skipcomment;
|
in >> skipcomment;
|
||||||
while ( !in.eof() ) {
|
while ( !in.eof() ) {
|
||||||
string name;
|
string name;
|
||||||
|
@ -50,14 +50,14 @@ int load_usgs_map( const std::string& filename ) {
|
||||||
usgs_map.push_back( get_area_type( name ) );
|
usgs_map.push_back( get_area_type( name ) );
|
||||||
in >> skipcomment;
|
in >> skipcomment;
|
||||||
}
|
}
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate USGS land cover values into TerraGear area types.
|
// Translate USGS land cover values into TerraGear area types.
|
||||||
AreaType translateUSGSCover (int usgs_value)
|
AreaType translateUSGSCover (unsigned int usgs_value)
|
||||||
{
|
{
|
||||||
if ( 0<usgs_value && usgs_value<usgs_map.size() ) {
|
if ( 0<usgs_value && usgs_value<usgs_map.size() ) {
|
||||||
return usgs_map[usgs_value-1];
|
return usgs_map[usgs_value-1];
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
|
||||||
#ifndef _USGS_HXX
|
#ifndef _USGS_HXX
|
||||||
#define _USGS_HXX
|
#define _USGS_HXX
|
||||||
|
@ -29,7 +29,6 @@
|
||||||
#include "priorities.hxx"
|
#include "priorities.hxx"
|
||||||
|
|
||||||
int load_usgs_map( const std::string& filename );
|
int load_usgs_map( const std::string& filename );
|
||||||
AreaType translateUSGSCover( int usgs_value );
|
AreaType translateUSGSCover( unsigned int usgs_value );
|
||||||
|
|
||||||
#endif // _USGS_HXX
|
#endif // _USGS_HXX
|
||||||
|
|
||||||
|
|
|
@ -66,14 +66,14 @@ int make_socket (unsigned short int* port) {
|
||||||
int sock;
|
int sock;
|
||||||
struct sockaddr_in name;
|
struct sockaddr_in name;
|
||||||
socklen_t length;
|
socklen_t length;
|
||||||
|
|
||||||
// Create the socket.
|
// Create the socket.
|
||||||
sock = socket (PF_INET, SOCK_STREAM, 0);
|
sock = socket (PF_INET, SOCK_STREAM, 0);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
perror ("socket");
|
perror ("socket");
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give the socket a name.
|
// Give the socket a name.
|
||||||
name.sin_family = AF_INET;
|
name.sin_family = AF_INET;
|
||||||
name.sin_addr.s_addr = INADDR_ANY;
|
name.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
@ -83,7 +83,7 @@ int make_socket (unsigned short int* port) {
|
||||||
perror ("bind");
|
perror ("bind");
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the assigned port number
|
// Find the assigned port number
|
||||||
length = sizeof(struct sockaddr_in);
|
length = sizeof(struct sockaddr_in);
|
||||||
if ( getsockname(sock, (struct sockaddr *) &name, &length) ) {
|
if ( getsockname(sock, (struct sockaddr *) &name, &length) ) {
|
||||||
|
@ -154,7 +154,7 @@ void init_tile_count( const string& chunk ) {
|
||||||
start_lat = atof( lats.substr(1,2).c_str() );
|
start_lat = atof( lats.substr(1,2).c_str() );
|
||||||
if ( vert == "s" ) { start_lat *= -1; }
|
if ( vert == "s" ) { start_lat *= -1; }
|
||||||
|
|
||||||
cout << "start_lon = " << start_lon << " start_lat = " << start_lat
|
cout << "start_lon = " << start_lon << " start_lat = " << start_lat
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ long int get_next_tile() {
|
||||||
// lon = -82 + (shift_over*dx) + (dx*0.5);
|
// lon = -82 + (shift_over*dx) + (dx*0.5);
|
||||||
lon = start_lon + (shift_over*dx) + (dx*0.5);
|
lon = start_lon + (shift_over*dx) + (dx*0.5);
|
||||||
|
|
||||||
cout << "starting pass = " << pass
|
cout << "starting pass = " << pass
|
||||||
<< " with lat = " << lat << " lon = " << lon << endl;
|
<< " with lat = " << lat << " lon = " << lon << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ long int get_next_tile() {
|
||||||
<< (double)global_counter / (double)(seconds - start_seconds)
|
<< (double)global_counter / (double)(seconds - start_seconds)
|
||||||
<< endl;
|
<< endl;
|
||||||
cout << "Overall tile per hour rate = "
|
cout << "Overall tile per hour rate = "
|
||||||
<< (double)global_counter * 3600.0 /
|
<< (double)global_counter * 3600.0 /
|
||||||
(double)(seconds - start_seconds)
|
(double)(seconds - start_seconds)
|
||||||
<< endl;
|
<< endl;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
@ -298,7 +298,7 @@ void log_failed_tile( const string& path, long int tile ) {
|
||||||
void usage( const string name ) {
|
void usage( const string name ) {
|
||||||
cout << "Usage: " << name
|
cout << "Usage: " << name
|
||||||
<< "[--width=<width> --height=<height>] "
|
<< "[--width=<width> --height=<height>] "
|
||||||
<< " <work_base> <output_base> chunk1 chunk2 ..."
|
<< " <work_base> <output_base> chunk1 chunk2 ..."
|
||||||
<< endl;
|
<< endl;
|
||||||
cout << "\twhere chunk represents the south west corner of the area"
|
cout << "\twhere chunk represents the south west corner of the area"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
@ -363,7 +363,7 @@ DWORD WINAPI
|
||||||
ThreadProc(void* p)
|
ThreadProc(void* p)
|
||||||
{
|
{
|
||||||
DWORD pN1;
|
DWORD pN1;
|
||||||
ULONG_PTR pN2;
|
ULONG_PTR pN2;
|
||||||
OVERLAPPED* pOverLapped;
|
OVERLAPPED* pOverLapped;
|
||||||
|
|
||||||
while( GetQueuedCompletionStatus(gIoPort, &pN1, &pN2, &pOverLapped, INFINITE)) {
|
while( GetQueuedCompletionStatus(gIoPort, &pN1, &pN2, &pOverLapped, INFINITE)) {
|
||||||
|
@ -386,7 +386,7 @@ ThreadProc(void* p)
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
int arg_counter;
|
int arg_counter;
|
||||||
long int next_tile;
|
long int next_tile;
|
||||||
int sock, msgsock, length, pid;
|
int sock, msgsock;
|
||||||
fd_set ready;
|
fd_set ready;
|
||||||
short unsigned int port;
|
short unsigned int port;
|
||||||
|
|
||||||
|
@ -457,7 +457,7 @@ int main( int argc, char **argv ) {
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
FD_ZERO(&ready);
|
FD_ZERO(&ready);
|
||||||
FD_SET(sock, &ready);
|
FD_SET(sock, &ready);
|
||||||
|
|
||||||
// block until we get some input on sock
|
// block until we get some input on sock
|
||||||
select(sock+1, &ready, 0, 0, NULL);
|
select(sock+1, &ready, 0, 0, NULL);
|
||||||
|
|
||||||
|
@ -476,9 +476,9 @@ int main( int argc, char **argv ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Bucket = " << SGBucket(next_tile)
|
cout << "Bucket = " << SGBucket(next_tile)
|
||||||
<< " (" << pass << ")" << endl;
|
<< " (" << pass << ")" << endl;
|
||||||
|
|
||||||
log_pending_tile( status_dir, next_tile );
|
log_pending_tile( status_dir, next_tile );
|
||||||
// cout << "next tile = " << next_tile << endl;;
|
// cout << "next tile = " << next_tile << endl;;
|
||||||
|
|
||||||
|
@ -487,7 +487,7 @@ int main( int argc, char **argv ) {
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
// spawn a child
|
// spawn a child
|
||||||
pid = fork();
|
int pid = fork();
|
||||||
|
|
||||||
if ( pid < 0 ) {
|
if ( pid < 0 ) {
|
||||||
// error
|
// error
|
||||||
|
@ -500,7 +500,7 @@ int main( int argc, char **argv ) {
|
||||||
// clean up all of our zombie children
|
// clean up all of our zombie children
|
||||||
int status;
|
int status;
|
||||||
while ( (pid = waitpid( WAIT_ANY, &status, WNOHANG )) > 0 ) {
|
while ( (pid = waitpid( WAIT_ANY, &status, WNOHANG )) > 0 ) {
|
||||||
// cout << "waitpid(): pid = " << pid
|
// cout << "waitpid(): pid = " << pid
|
||||||
// << " status = " << status << endl;
|
// << " status = " << status << endl;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -71,7 +71,7 @@ bool endswith(const std::string& s, const std::string& suffix) {
|
||||||
|
|
||||||
OGRLayer* create_layer(const std::string& material) {
|
OGRLayer* create_layer(const std::string& material) {
|
||||||
OGRLayer* layer;
|
OGRLayer* layer;
|
||||||
|
|
||||||
OGRSpatialReference srs;
|
OGRSpatialReference srs;
|
||||||
srs.SetWellKnownGeogCS("WGS84");
|
srs.SetWellKnownGeogCS("WGS84");
|
||||||
layer=datasource->CreateLayer(material.c_str(),&srs,wkbPolygon25D,NULL);
|
layer=datasource->CreateLayer(material.c_str(),&srs,wkbPolygon25D,NULL);
|
||||||
|
@ -79,27 +79,27 @@ OGRLayer* create_layer(const std::string& material) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of layer '" << material << "' failed");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of layer '" << material << "' failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
OGRFieldDefn materialField("Material", OFTString);
|
OGRFieldDefn materialField("Material", OFTString);
|
||||||
materialField.SetWidth(128);
|
materialField.SetWidth(128);
|
||||||
|
|
||||||
OGRFieldDefn fileField("File",OFTString);
|
OGRFieldDefn fileField("File",OFTString);
|
||||||
fileField.SetWidth(256);
|
fileField.SetWidth(256);
|
||||||
|
|
||||||
if( layer->CreateField( &materialField ) != OGRERR_NONE ) {
|
if( layer->CreateField( &materialField ) != OGRERR_NONE ) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of field 'Material' failed");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of field 'Material' failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( layer->CreateField( &fileField ) != OGRERR_NONE ) {
|
if( layer->CreateField( &fileField ) != OGRERR_NONE ) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of field 'Material' failed");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of field 'Material' failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return layer;
|
return layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
OGRLayer* create_pointsLayer() {
|
OGRLayer* create_pointsLayer() {
|
||||||
OGRLayer* layer;
|
OGRLayer* layer;
|
||||||
|
|
||||||
OGRSpatialReference srs;
|
OGRSpatialReference srs;
|
||||||
srs.SetWellKnownGeogCS("WGS84");
|
srs.SetWellKnownGeogCS("WGS84");
|
||||||
layer=datasource->CreateLayer("points",&srs,wkbPoint,NULL);
|
layer=datasource->CreateLayer("points",&srs,wkbPoint,NULL);
|
||||||
|
@ -107,21 +107,21 @@ OGRLayer* create_pointsLayer() {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of layer 'points' failed");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of layer 'points' failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
OGRFieldDefn materialField("Material", OFTString);
|
OGRFieldDefn materialField("Material", OFTString);
|
||||||
materialField.SetWidth(128);
|
materialField.SetWidth(128);
|
||||||
|
|
||||||
OGRFieldDefn fileField("File",OFTString);
|
OGRFieldDefn fileField("File",OFTString);
|
||||||
fileField.SetWidth(256);
|
fileField.SetWidth(256);
|
||||||
|
|
||||||
if( layer->CreateField( &materialField ) != OGRERR_NONE ) {
|
if( layer->CreateField( &materialField ) != OGRERR_NONE ) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of field 'Material' failed");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of field 'Material' failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( layer->CreateField( &fileField ) != OGRERR_NONE ) {
|
if( layer->CreateField( &fileField ) != OGRERR_NONE ) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of field 'Material' failed");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Creation of field 'Material' failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return layer;
|
return layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ OGRLayer* get_layer_for_material(const std::string& material) {
|
||||||
}
|
}
|
||||||
return defaultLayer;
|
return defaultLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
OGRLayer* layer;
|
OGRLayer* layer;
|
||||||
LayerMap::iterator it=layerMap.find(material);
|
LayerMap::iterator it=layerMap.find(material);
|
||||||
if (it==layerMap.end()) {
|
if (it==layerMap.end()) {
|
||||||
|
@ -159,26 +159,26 @@ OGRLinearRing* make_ring_from_fan(const int_list& fan, const std::vector<Point3D
|
||||||
point->setX(node.x());
|
point->setX(node.x());
|
||||||
point->setY(node.y());
|
point->setY(node.y());
|
||||||
point->setZ(node.z());
|
point->setZ(node.z());
|
||||||
|
|
||||||
ring->addPoint(point);
|
ring->addPoint(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
ring->closeRings();
|
ring->closeRings();
|
||||||
|
|
||||||
return ring;
|
return ring;
|
||||||
}
|
}
|
||||||
|
|
||||||
OGRLinearRing* make_ring_from_strip(const int_list& strip, const std::vector<Point3D>& nodes) {
|
OGRLinearRing* make_ring_from_strip(const int_list& strip, const std::vector<Point3D>& nodes) {
|
||||||
OGRLinearRing* ring = new OGRLinearRing();
|
OGRLinearRing* ring = new OGRLinearRing();
|
||||||
const size_t vertex_count = strip.size();
|
const size_t vertex_count = strip.size();
|
||||||
int i;
|
unsigned int i;
|
||||||
for (i=0;i<vertex_count;i+=2) {
|
for (i=0;i<vertex_count;i+=2) {
|
||||||
OGRPoint *point=new OGRPoint();
|
OGRPoint *point=new OGRPoint();
|
||||||
const Point3D& node = nodes[strip[i]];
|
const Point3D& node = nodes[strip[i]];
|
||||||
point->setX(node.x());
|
point->setX(node.x());
|
||||||
point->setY(node.y());
|
point->setY(node.y());
|
||||||
point->setZ(node.z());
|
point->setZ(node.z());
|
||||||
|
|
||||||
ring->addPoint(point);
|
ring->addPoint(point);
|
||||||
}
|
}
|
||||||
for (i--;i>0;i-=2) {
|
for (i--;i>0;i-=2) {
|
||||||
|
@ -187,13 +187,13 @@ OGRLinearRing* make_ring_from_strip(const int_list& strip, const std::vector<Poi
|
||||||
point->setX(node.x());
|
point->setX(node.x());
|
||||||
point->setY(node.y());
|
point->setY(node.y());
|
||||||
point->setZ(node.z());
|
point->setZ(node.z());
|
||||||
|
|
||||||
ring->addPoint(point);
|
ring->addPoint(point);
|
||||||
}
|
}
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
|
|
||||||
ring->closeRings();
|
ring->closeRings();
|
||||||
|
|
||||||
return ring;
|
return ring;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,30 +204,30 @@ void make_feature_from_polygon(OGRPolygon* polygon, const std::string& material,
|
||||||
feature->SetField("Material", material.c_str());
|
feature->SetField("Material", material.c_str());
|
||||||
feature->SetField("File", path.c_str());
|
feature->SetField("File", path.c_str());
|
||||||
feature->SetGeometry(polygon);
|
feature->SetGeometry(polygon);
|
||||||
|
|
||||||
if( layer->CreateFeature( feature ) != OGRERR_NONE )
|
if( layer->CreateFeature( feature ) != OGRERR_NONE )
|
||||||
{
|
{
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to create feature in shapefile");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to create feature in shapefile");
|
||||||
}
|
}
|
||||||
|
|
||||||
OGRFeature::DestroyFeature(feature);
|
OGRFeature::DestroyFeature(feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
void make_feature_from_ring(OGRLinearRing* ring, const std::string& material, const std::string& path) {
|
void make_feature_from_ring(OGRLinearRing* ring, const std::string& material, const std::string& path) {
|
||||||
OGRPolygon* polygon = new OGRPolygon();
|
OGRPolygon* polygon = new OGRPolygon();
|
||||||
polygon->addRingDirectly(ring);
|
polygon->addRingDirectly(ring);
|
||||||
|
|
||||||
make_feature_from_polygon(polygon, material, path);
|
make_feature_from_polygon(polygon, material, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert_triangles(const std::string& path, const group_list& verts, const string_list& materials, const std::vector<Point3D>& wgs84_nodes) {
|
void convert_triangles(const std::string& path, const group_list& verts, const string_list& materials, const std::vector<Point3D>& wgs84_nodes) {
|
||||||
const size_t groups_count = verts.size();
|
const size_t groups_count = verts.size();
|
||||||
|
|
||||||
for (int i=0;i<groups_count;i++) {
|
for (unsigned int i=0;i<groups_count;i++) {
|
||||||
const string& material = materials[i];
|
const string& material = materials[i];
|
||||||
const int_list& tri_verts = verts[i];
|
const int_list& tri_verts = verts[i];
|
||||||
const size_t vertices = tri_verts.size();
|
const size_t vertices = tri_verts.size();
|
||||||
for (int j=0;j<vertices;j+=3) {
|
for (unsigned int j=0;j<vertices;j+=3) {
|
||||||
OGRLinearRing* ring = new OGRLinearRing();
|
OGRLinearRing* ring = new OGRLinearRing();
|
||||||
for (int k=0;k<3;k++) {
|
for (int k=0;k<3;k++) {
|
||||||
OGRPoint *point=new OGRPoint();
|
OGRPoint *point=new OGRPoint();
|
||||||
|
@ -235,7 +235,7 @@ void convert_triangles(const std::string& path, const group_list& verts, const s
|
||||||
point->setX(node.x());
|
point->setX(node.x());
|
||||||
point->setY(node.y());
|
point->setY(node.y());
|
||||||
point->setZ(node.z());
|
point->setZ(node.z());
|
||||||
|
|
||||||
ring->addPoint(point);
|
ring->addPoint(point);
|
||||||
}
|
}
|
||||||
ring->closeRings();
|
ring->closeRings();
|
||||||
|
@ -246,8 +246,8 @@ void convert_triangles(const std::string& path, const group_list& verts, const s
|
||||||
|
|
||||||
void convert_triangle_fans(const std::string& path, const group_list& verts, const string_list& materials, const std::vector<Point3D>& wgs84_nodes) {
|
void convert_triangle_fans(const std::string& path, const group_list& verts, const string_list& materials, const std::vector<Point3D>& wgs84_nodes) {
|
||||||
const size_t groups_count = verts.size();
|
const size_t groups_count = verts.size();
|
||||||
|
|
||||||
for (int i=0;i<groups_count;i++) {
|
for (unsigned int i=0;i<groups_count;i++) {
|
||||||
const string& material = materials[i];
|
const string& material = materials[i];
|
||||||
OGRLinearRing* ring = make_ring_from_fan(verts[i], wgs84_nodes);
|
OGRLinearRing* ring = make_ring_from_fan(verts[i], wgs84_nodes);
|
||||||
make_feature_from_ring(ring, material, path);
|
make_feature_from_ring(ring, material, path);
|
||||||
|
@ -256,8 +256,8 @@ void convert_triangle_fans(const std::string& path, const group_list& verts, con
|
||||||
|
|
||||||
void convert_triangle_strips(const std::string& path, const group_list& verts, const string_list& materials, const std::vector<Point3D>& wgs84_nodes) {
|
void convert_triangle_strips(const std::string& path, const group_list& verts, const string_list& materials, const std::vector<Point3D>& wgs84_nodes) {
|
||||||
const size_t groups_count = verts.size();
|
const size_t groups_count = verts.size();
|
||||||
|
|
||||||
for (int i=0;i<groups_count;i++) {
|
for (unsigned int i=0;i<groups_count;i++) {
|
||||||
const string& material = materials[i];
|
const string& material = materials[i];
|
||||||
OGRLinearRing* ring = make_ring_from_strip(verts[i], wgs84_nodes);
|
OGRLinearRing* ring = make_ring_from_strip(verts[i], wgs84_nodes);
|
||||||
make_feature_from_ring(ring, material, path);
|
make_feature_from_ring(ring, material, path);
|
||||||
|
@ -269,12 +269,12 @@ void process_scenery_file(const std::string& path) {
|
||||||
if (!binObject.read_bin(path)) {
|
if (!binObject.read_bin(path)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SGVec3d gbs_center = binObject.get_gbs_center();
|
SGVec3d gbs_center = binObject.get_gbs_center();
|
||||||
const std::vector<SGVec3d>& wgs84_nodes = binObject.get_wgs84_nodes();
|
const std::vector<SGVec3d>& wgs84_nodes = binObject.get_wgs84_nodes();
|
||||||
std::vector<Point3D> geod_nodes;
|
std::vector<Point3D> geod_nodes;
|
||||||
const size_t node_count = wgs84_nodes.size();
|
const size_t node_count = wgs84_nodes.size();
|
||||||
for (int i=0;i<node_count;i++) {
|
for (unsigned int i=0;i<node_count;i++) {
|
||||||
SGVec3d wgs84 = wgs84_nodes[i];
|
SGVec3d wgs84 = wgs84_nodes[i];
|
||||||
Point3D raw = Point3D( gbs_center.x() + wgs84.x(),
|
Point3D raw = Point3D( gbs_center.x() + wgs84.x(),
|
||||||
gbs_center.y() + wgs84.y(),
|
gbs_center.y() + wgs84.y(),
|
||||||
|
@ -285,19 +285,19 @@ void process_scenery_file(const std::string& path) {
|
||||||
radians.z() );
|
radians.z() );
|
||||||
geod_nodes.push_back(geod);
|
geod_nodes.push_back(geod);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert individual triangles */
|
/* Convert individual triangles */
|
||||||
convert_triangles(path,
|
convert_triangles(path,
|
||||||
binObject.get_tris_v(),
|
binObject.get_tris_v(),
|
||||||
binObject.get_tri_materials(),
|
binObject.get_tri_materials(),
|
||||||
geod_nodes);
|
geod_nodes);
|
||||||
|
|
||||||
/* Convert triangle fans */
|
/* Convert triangle fans */
|
||||||
convert_triangle_fans(path,
|
convert_triangle_fans(path,
|
||||||
binObject.get_fans_v(),
|
binObject.get_fans_v(),
|
||||||
binObject.get_fan_materials(),
|
binObject.get_fan_materials(),
|
||||||
geod_nodes);
|
geod_nodes);
|
||||||
|
|
||||||
/* Convert triangle strips */
|
/* Convert triangle strips */
|
||||||
convert_triangle_strips(path,
|
convert_triangle_strips(path,
|
||||||
binObject.get_strips_v(),
|
binObject.get_strips_v(),
|
||||||
|
@ -307,9 +307,9 @@ void process_scenery_file(const std::string& path) {
|
||||||
|
|
||||||
void process_polygon_file(const std::string& path) {
|
void process_polygon_file(const std::string& path) {
|
||||||
SG_LOG(SG_GENERAL, SG_INFO, "Loading polygon file " << path);
|
SG_LOG(SG_GENERAL, SG_INFO, "Loading polygon file " << path);
|
||||||
|
|
||||||
sg_gzifstream in( path );
|
sg_gzifstream in( path );
|
||||||
|
|
||||||
while (!in.eof()) {
|
while (!in.eof()) {
|
||||||
string first_line,material;
|
string first_line,material;
|
||||||
bool poly3d=false;
|
bool poly3d=false;
|
||||||
|
@ -325,35 +325,35 @@ void process_polygon_file(const std::string& path) {
|
||||||
poly3d = false;
|
poly3d = false;
|
||||||
material=first_line;
|
material=first_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
int contours;
|
int contours;
|
||||||
in >> contours;
|
in >> contours;
|
||||||
|
|
||||||
OGRPolygon* polygon=new OGRPolygon();
|
OGRPolygon* polygon=new OGRPolygon();
|
||||||
|
|
||||||
for (int contour=0;contour<contours;contour++) {
|
for (int contour=0;contour<contours;contour++) {
|
||||||
int count,hole_flag;
|
int count,hole_flag;
|
||||||
bool skip_ring=false;
|
bool skip_ring=false;
|
||||||
|
|
||||||
in >> count;
|
in >> count;
|
||||||
|
|
||||||
if (count<3) {
|
if (count<3) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Polygon with less than 3 points");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Polygon with less than 3 points");
|
||||||
skip_ring=true;
|
skip_ring=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
in >> hole_flag;
|
in >> hole_flag;
|
||||||
|
|
||||||
// FIXME: Current we ignore the hole-flag and instead assume
|
// FIXME: Current we ignore the hole-flag and instead assume
|
||||||
// that the first ring is not a hole and the rest
|
// that the first ring is not a hole and the rest
|
||||||
// are holes
|
// are holes
|
||||||
|
|
||||||
OGRLinearRing *ring=new OGRLinearRing();
|
OGRLinearRing *ring=new OGRLinearRing();
|
||||||
|
|
||||||
for (int pt=0;pt<count;pt++) {
|
for (int pt=0;pt<count;pt++) {
|
||||||
OGRPoint *point=new OGRPoint();
|
OGRPoint *point=new OGRPoint();
|
||||||
double x,y,z;
|
double x,y,z;
|
||||||
|
|
||||||
in >> x >> y;
|
in >> x >> y;
|
||||||
point->setX(x);
|
point->setX(x);
|
||||||
point->setY(y);
|
point->setY(y);
|
||||||
|
@ -363,51 +363,51 @@ void process_polygon_file(const std::string& path) {
|
||||||
} else {
|
} else {
|
||||||
point->setZ(0.0);
|
point->setZ(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ring->addPoint(point);
|
ring->addPoint(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
ring->closeRings();
|
ring->closeRings();
|
||||||
|
|
||||||
if (!skip_ring)
|
if (!skip_ring)
|
||||||
polygon->addRingDirectly(ring);
|
polygon->addRingDirectly(ring);
|
||||||
}
|
}
|
||||||
|
|
||||||
make_feature_from_polygon(polygon, material, path);
|
make_feature_from_polygon(polygon, material, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_points_file(const std::string& path) {
|
void process_points_file(const std::string& path) {
|
||||||
SG_LOG(SG_GENERAL, SG_INFO, "Loading points file " << path);
|
SG_LOG(SG_GENERAL, SG_INFO, "Loading points file " << path);
|
||||||
|
|
||||||
sg_gzifstream in( path );
|
sg_gzifstream in( path );
|
||||||
|
|
||||||
if (pointsLayer==NULL)
|
if (pointsLayer==NULL)
|
||||||
{
|
{
|
||||||
pointsLayer=create_pointsLayer();
|
pointsLayer=create_pointsLayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!in.eof()) {
|
while (!in.eof()) {
|
||||||
std::string material;
|
std::string material;
|
||||||
double x,y;
|
double x,y;
|
||||||
in >> x >> y >> material;
|
in >> x >> y >> material;
|
||||||
|
|
||||||
if (in.eof())
|
if (in.eof())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
OGRPoint* point=new OGRPoint(x,y);
|
OGRPoint* point=new OGRPoint(x,y);
|
||||||
|
|
||||||
OGRFeature* feature;
|
OGRFeature* feature;
|
||||||
feature = new OGRFeature( pointsLayer->GetLayerDefn() );
|
feature = new OGRFeature( pointsLayer->GetLayerDefn() );
|
||||||
feature->SetField("Material", material.c_str());
|
feature->SetField("Material", material.c_str());
|
||||||
feature->SetField("File", path.c_str());
|
feature->SetField("File", path.c_str());
|
||||||
feature->SetGeometry(point);
|
feature->SetGeometry(point);
|
||||||
|
|
||||||
if( pointsLayer->CreateFeature( feature ) != OGRERR_NONE )
|
if( pointsLayer->CreateFeature( feature ) != OGRERR_NONE )
|
||||||
{
|
{
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to create feature in shapefile");
|
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to create feature in shapefile");
|
||||||
}
|
}
|
||||||
|
|
||||||
OGRFeature::DestroyFeature(feature);
|
OGRFeature::DestroyFeature(feature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -422,17 +422,17 @@ void process_file(const SGPath& path)
|
||||||
BOOST_FOREACH(const SGPath& c, d.children(flags)) {
|
BOOST_FOREACH(const SGPath& c, d.children(flags)) {
|
||||||
process_file(c);
|
process_file(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string lext = path.complete_lower_extension();
|
string lext = path.complete_lower_extension();
|
||||||
if (lext == "pts") {
|
if (lext == "pts") {
|
||||||
process_points_file(path.str());
|
process_points_file(path.str());
|
||||||
} else if ((lext == "btg.gz") || (lext == "btg")) {
|
} else if ((lext == "btg.gz") || (lext == "btg")) {
|
||||||
process_scenery_file(path.str());
|
process_scenery_file(path.str());
|
||||||
} else if ((lext != "gz") && (lext != "arr") && (lext != "fit") &&
|
} else if ((lext != "gz") && (lext != "arr") && (lext != "fit") &&
|
||||||
(lext != "stg") && (lext != "ind"))
|
(lext != "stg") && (lext != "ind"))
|
||||||
{
|
{
|
||||||
// should be a polygon file
|
// should be a polygon file
|
||||||
process_polygon_file(path.str());
|
process_polygon_file(path.str());
|
||||||
|
@ -484,11 +484,11 @@ struct option options[]={
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
sglog().setLogLevels( SG_ALL, SG_DEBUG );
|
sglog().setLogLevels( SG_ALL, SG_DEBUG );
|
||||||
|
|
||||||
OGRRegisterAll();
|
OGRRegisterAll();
|
||||||
|
|
||||||
int option;
|
int option;
|
||||||
|
|
||||||
while ((option=getopt_long(argc,argv,"hvsf:",options,NULL))!=-1) {
|
while ((option=getopt_long(argc,argv,"hvsf:",options,NULL))!=-1) {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -509,37 +509,37 @@ int main(int argc, char** argv) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind+1>argc) {
|
if (optind+1>argc) {
|
||||||
usage(argv[0],"A datasource must be specified");
|
usage(argv[0],"A datasource must be specified");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind+2>argc) {
|
if (optind+2>argc) {
|
||||||
usage(argv[0],"At least one input file must be specified");
|
usage(argv[0],"At least one input file must be specified");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* dst_datasource=argv[optind++];
|
const char* dst_datasource=argv[optind++];
|
||||||
OGRSFDriver *ogrdriver;
|
OGRSFDriver *ogrdriver;
|
||||||
|
|
||||||
ogrdriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(format_name);
|
ogrdriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(format_name);
|
||||||
if (!ogrdriver) {
|
if (!ogrdriver) {
|
||||||
usage(argv[0],std::string("Unknown datasource format driver:")+format_name);
|
usage(argv[0],std::string("Unknown datasource format driver:")+format_name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource = ogrdriver->CreateDataSource(dst_datasource,NULL);
|
datasource = ogrdriver->CreateDataSource(dst_datasource,NULL);
|
||||||
if (!datasource) {
|
if (!datasource) {
|
||||||
usage(argv[0],std::string("Unable to create datasource:")+dst_datasource);
|
usage(argv[0],std::string("Unable to create datasource:")+dst_datasource);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=optind;i<argc;i++) {
|
for (int i=optind;i<argc;i++) {
|
||||||
process_file(SGPath(argv[i]));
|
process_file(SGPath(argv[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
OGRDataSource::DestroyDataSource( datasource );
|
OGRDataSource::DestroyDataSource( datasource );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue