mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-11-24 16:10:18 +00:00
Write all contours from vector
This commit is contained in:
parent
cf72fbfefa
commit
040e011a66
82
src/main.cpp
82
src/main.cpp
@ -34,7 +34,7 @@ std::vector<CaseMap> vector_casemap(HeightMap* heightmap, int interval)
|
|||||||
{
|
{
|
||||||
int num_contours = (heightmap->max - heightmap->min)/interval;
|
int num_contours = (heightmap->max - heightmap->min)/interval;
|
||||||
std::vector<CaseMap> vector_contours;
|
std::vector<CaseMap> vector_contours;
|
||||||
omp_set_num_threads(8);
|
omp_set_num_threads(12);
|
||||||
|
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
{
|
{
|
||||||
@ -43,7 +43,7 @@ omp_set_num_threads(8);
|
|||||||
for (int i = 1; i <= num_contours; i++)
|
for (int i = 1; i <= num_contours; i++)
|
||||||
{
|
{
|
||||||
vec_private.push_back(produce_casemap(heightmap, heightmap->min + interval*i));
|
vec_private.push_back(produce_casemap(heightmap, heightmap->min + interval*i));
|
||||||
std::cout << "Execute thread " << omp_get_num_threads << " ";
|
std::cout << "Execute thread " << omp_get_num_threads() << " ";
|
||||||
}
|
}
|
||||||
#pragma omp critical
|
#pragma omp critical
|
||||||
vector_contours.insert(vector_contours.end(), vec_private.begin(), vec_private.end());
|
vector_contours.insert(vector_contours.end(), vec_private.begin(), vec_private.end());
|
||||||
@ -52,7 +52,7 @@ omp_set_num_threads(8);
|
|||||||
return vector_contours;
|
return vector_contours;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_output_file(CaseMap* casemap, const char *filepath)
|
void write_output_file(std::vector<CaseMap> casemaps, const char *filepath)
|
||||||
{
|
{
|
||||||
|
|
||||||
const char *pszDriverName = "ESRI Shapefile";
|
const char *pszDriverName = "ESRI Shapefile";
|
||||||
@ -78,7 +78,7 @@ void write_output_file(CaseMap* casemap, const char *filepath)
|
|||||||
|
|
||||||
OGRLayer *poLayer;
|
OGRLayer *poLayer;
|
||||||
|
|
||||||
poLayer = poDS->CreateLayer( "contours", &casemap->reference_system, wkbPoint, NULL );
|
poLayer = poDS->CreateLayer( "contours", &(casemaps[0]).reference_system, wkbPoint, NULL );
|
||||||
if( poLayer == NULL )
|
if( poLayer == NULL )
|
||||||
{
|
{
|
||||||
printf( "Layer creation failed.\n" );
|
printf( "Layer creation failed.\n" );
|
||||||
@ -94,41 +94,44 @@ void write_output_file(CaseMap* casemap, const char *filepath)
|
|||||||
printf( "Creating Name field failed.\n" );
|
printf( "Creating Name field failed.\n" );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
for (int j = 0; j < casemaps.size(); j++)
|
||||||
for (int i = 0; i<casemap->height*casemap->width; i++) {
|
{
|
||||||
if (*(casemap->cases + i) != 0 && *(casemap->cases + i) != 15)
|
CaseMap* casemap = &casemaps[j];
|
||||||
{
|
for (int i = 0; i<casemap->height*casemap->width; i++) {
|
||||||
int x_int = i%casemap->width;
|
if (*(casemap->cases + i) != 0 && *(casemap->cases + i) != 15)
|
||||||
int y_int = casemap->height*casemap->width - i/casemap->width;
|
|
||||||
double x = double(x_int);
|
|
||||||
double y = double(y_int);
|
|
||||||
|
|
||||||
OGRFeature *poFeature;
|
|
||||||
|
|
||||||
poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
|
|
||||||
poFeature->SetField( "Name", *(casemap->cases + i) );
|
|
||||||
|
|
||||||
//OGRSpatialReference local;
|
|
||||||
|
|
||||||
//auto poCT = OGRCreateCoordinateTransformation( &local, &casemap->reference_system );
|
|
||||||
|
|
||||||
/*
|
|
||||||
if( poCT == NULL || !poCT->Transform( 1, &x, &y ) )
|
|
||||||
printf( "Transformation failed.\n" );
|
|
||||||
*/
|
|
||||||
OGRPoint pt;
|
|
||||||
pt.setX( x );
|
|
||||||
pt.setY( y );
|
|
||||||
|
|
||||||
poFeature->SetGeometry( &pt );
|
|
||||||
|
|
||||||
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
|
|
||||||
{
|
{
|
||||||
printf( "Failed to create feature in shapefile.\n" );
|
int x_int = i%casemap->width;
|
||||||
exit( 1 );
|
int y_int = casemap->height*casemap->width - i/casemap->width;
|
||||||
}
|
double x = double(x_int);
|
||||||
|
double y = double(y_int);
|
||||||
|
|
||||||
OGRFeature::DestroyFeature( poFeature );
|
OGRFeature *poFeature;
|
||||||
|
|
||||||
|
poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
|
||||||
|
poFeature->SetField( "Name", *(casemap->cases + i) );
|
||||||
|
|
||||||
|
//OGRSpatialReference local;
|
||||||
|
|
||||||
|
//auto poCT = OGRCreateCoordinateTransformation( &local, &casemap->reference_system );
|
||||||
|
|
||||||
|
/*
|
||||||
|
if( poCT == NULL || !poCT->Transform( 1, &x, &y ) )
|
||||||
|
printf( "Transformation failed.\n" );
|
||||||
|
*/
|
||||||
|
OGRPoint pt;
|
||||||
|
pt.setX( x );
|
||||||
|
pt.setY( y );
|
||||||
|
|
||||||
|
poFeature->SetGeometry( &pt );
|
||||||
|
|
||||||
|
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
|
||||||
|
{
|
||||||
|
printf( "Failed to create feature in shapefile.\n" );
|
||||||
|
exit( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
OGRFeature::DestroyFeature( poFeature );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,6 +168,7 @@ int main(int argc, const char* argv[])
|
|||||||
//std::cout << "\n";
|
//std::cout << "\n";
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
write_output_file(&casemap, "out.shp");
|
|
||||||
vector_casemap(&map, 1);
|
auto casemaps = vector_casemap(&map, 5);
|
||||||
|
write_output_file(casemaps, "out.shp");
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user