Start to implement line drawing

This commit is contained in:
Trygve 2024-04-26 15:40:09 +02:00
parent 0485253893
commit ee0b87c2b3

View File

@ -1,6 +1,9 @@
#include "contour_creator.hh"
#include <gdal/ogr_api.h>
#include "ogrsf_frmts.h"
#include <gdal/ogr_core.h>
#include <gdal/ogr_feature.h>
#include <gdal/ogr_geometry.h>
#include <iostream>
#include <ostream>
#include <vector>
@ -86,7 +89,7 @@ void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
OGRLayer *poLayer;
poLayer = poDS->CreateLayer( "contours", &(cellmaps[0]).reference_system, wkbPoint, NULL );
poLayer = poDS->CreateLayer( "contours", &(cellmaps[0]).reference_system, wkbLineString, NULL );
if( poLayer == NULL )
{
printf( "Layer creation failed.\n" );
@ -105,41 +108,41 @@ void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
for (int j = 0; j < cellmaps.size(); j++)
{
CellMap* cellmap = &cellmaps[j];
for (int i = 0; i<cellmap->height*cellmap->width; i++) {
OGRFeature *feature;
OGRLineString *geometry;
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
feature->SetField( "Name", j );
for (int i = 0; i < cellmap->height*cellmap->width; i++)
{
if (*(cellmap->cells + i) != 0 && *(cellmap->cells + i) != 15)
{
OGRFeature *poFeature;
poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
poFeature->SetField( "Name", *(cellmap->cells + i) );
//OGRSpatialReference local;
//auto poCT = OGRCreateCoordinateTransformation( &local, &cellmap->reference_system );
/*
if( poCT == NULL || !poCT->Transform( 1, &x, &y ) )
printf( "Transformation failed.\n" );
*/
OGRPoint pt;
int x_raw = i%cellmap->width;
int y_raw = i/cellmap->width;
std::cout << "🤬"; std::cout.flush();
auto [x, y] = local_to_projected(cellmap->geotransform, x_raw, y_raw);
pt.setX( x );
pt.setY( y );
poFeature->SetGeometry( &pt );
geometry->setPoint( i, x, y );
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
{
printf( "Failed to create feature in shapefile.\n" );
exit( 1 );
}
OGRFeature::DestroyFeature( poFeature );
}
}
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 );
}
GDALClose( poDS );