mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-11-21 23:00:18 +00:00
Changed file wrriting to use list of points
This commit is contained in:
parent
d046e18c43
commit
1dcfb0e737
73
src/main.cpp
73
src/main.cpp
@ -86,7 +86,7 @@ constexpr std::tuple<double, double, double, double> marching_squares_lookup(int
|
|||||||
case 14: return {0, 0.5, 0.5, 0};
|
case 14: return {0, 0.5, 0.5, 0};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
|
void write_output_file(std::vector<std::vector<Point>> all_points, const char *filepath, HeightMap* heightmap)
|
||||||
{
|
{
|
||||||
|
|
||||||
const char *pszDriverName = "GeoJSON";
|
const char *pszDriverName = "GeoJSON";
|
||||||
@ -112,7 +112,7 @@ void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
|
|||||||
|
|
||||||
OGRLayer *poLayer;
|
OGRLayer *poLayer;
|
||||||
|
|
||||||
poLayer = poDS->CreateLayer( "contours", &(cellmaps[0]).reference_system, wkbLineString, NULL );
|
poLayer = poDS->CreateLayer( "contours", /*&(cellmaps[0]).reference_system*/ NULL, wkbLineString, NULL );
|
||||||
if( poLayer == NULL )
|
if( poLayer == NULL )
|
||||||
{
|
{
|
||||||
printf( "Layer creation failed.\n" );
|
printf( "Layer creation failed.\n" );
|
||||||
@ -128,43 +128,52 @@ void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
|
|||||||
printf( "Creating Name field failed.\n" );
|
printf( "Creating Name field failed.\n" );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
for (int j = 0; j < cellmaps.size(); j++)
|
int width = heightmap->width -1;
|
||||||
|
int height = heightmap->height -1;
|
||||||
|
int size = width * height;
|
||||||
|
|
||||||
|
for (int j = 0; j < all_points.size(); j++)
|
||||||
{
|
{
|
||||||
CellMap* cellmap = &cellmaps[j];
|
OGRFeature *feature;
|
||||||
|
OGRLineString *geometry = new OGRLineString();
|
||||||
|
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
|
||||||
|
feature->SetField( "Name", j );
|
||||||
|
|
||||||
for (int i = 0; i < cellmap->height*cellmap->width; i++)
|
|
||||||
|
std::vector<Point> points = all_points[j];
|
||||||
|
|
||||||
|
for (int i = 0; i < points.size(); i++)
|
||||||
{
|
{
|
||||||
if (*(cellmap->cells + i) != 0 && *(cellmap->cells + i) != 15)
|
|
||||||
{
|
//int x_raw = i%width;
|
||||||
OGRFeature *feature;
|
//int y_raw = i/height;
|
||||||
OGRLineString *geometry = new OGRLineString();
|
int x_raw = points[i].x;
|
||||||
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
|
int y_raw = points[i].y;
|
||||||
feature->SetField( "Name", j );
|
auto [x, y] = local_to_projected(heightmap->geotransform, x_raw, y_raw);
|
||||||
int x_raw = i%cellmap->width;
|
//auto [x_bl, y_bl, x_tr, y_tr] = marching_squares_lookup(*(cellmap->cells + i) );
|
||||||
int y_raw = i/cellmap->width;
|
//std::cout << x << ", " << y << " ";
|
||||||
auto [x, y] = local_to_projected(cellmap->geotransform, x_raw, y_raw);
|
//geometry->setPoint( geometry->getNumPoints(), x+x_tr*0.25, y+y_tr*0.25 );
|
||||||
auto [x_bl, y_bl, x_tr, y_tr] = marching_squares_lookup(*(cellmap->cells + i) );
|
//geometry->setPoint( geometry->getNumPoints(), x+x_bl*0.25, y+y_bl*0.25 );
|
||||||
//std::cout << x << ", " << y << " ";
|
geometry->setPoint(geometry->getNumPoints(),x ,y );
|
||||||
geometry->setPoint( geometry->getNumPoints(), x+x_tr*0.25, y+y_tr*0.25 );
|
|
||||||
geometry->setPoint( geometry->getNumPoints(), x+x_bl*0.25, y+y_bl*0.25 );
|
|
||||||
|
|
||||||
|
|
||||||
if ( feature->SetGeometry(geometry) != OGRERR_NONE)
|
|
||||||
{
|
|
||||||
printf( "Failed to set geometry.\n" );
|
|
||||||
exit( 1 );
|
|
||||||
}
|
|
||||||
OGRGeometryFactory::destroyGeometry(geometry);
|
|
||||||
if( poLayer->CreateFeature( feature ) != OGRERR_NONE )
|
|
||||||
{
|
|
||||||
printf( "Failed to create feature in shapefile.\n" );
|
|
||||||
exit( 1 );
|
|
||||||
}
|
|
||||||
OGRFeature::DestroyFeature( feature );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( feature->SetGeometry(geometry) != OGRERR_NONE)
|
||||||
|
{
|
||||||
|
printf( "Failed to set geometry.\n" );
|
||||||
|
exit( 1 );
|
||||||
|
}
|
||||||
|
OGRGeometryFactory::destroyGeometry(geometry);
|
||||||
|
if( poLayer->CreateFeature( feature ) != OGRERR_NONE )
|
||||||
|
{
|
||||||
|
printf( "Failed to create feature in shapefile.\n" );
|
||||||
|
exit( 1 );
|
||||||
|
}
|
||||||
|
OGRFeature::DestroyFeature( feature );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,5 +193,5 @@ int main(int argc, const char* argv[])
|
|||||||
auto cellmap = produce_cellmap(&map, 40);
|
auto cellmap = produce_cellmap(&map, 40);
|
||||||
|
|
||||||
auto cellmaps = vector_cellmap(&map, 5);
|
auto cellmaps = vector_cellmap(&map, 5);
|
||||||
//write_output_file(cellmaps, "out.geojson");
|
write_output_file(cellmaps, "out.geojson", &map);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user