mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-11-21 23:00:18 +00:00
Start to implement line drawing
This commit is contained in:
parent
0485253893
commit
ee0b87c2b3
59
src/main.cpp
59
src/main.cpp
@ -1,6 +1,9 @@
|
|||||||
#include "contour_creator.hh"
|
#include "contour_creator.hh"
|
||||||
#include <gdal/ogr_api.h>
|
#include <gdal/ogr_api.h>
|
||||||
#include "ogrsf_frmts.h"
|
#include "ogrsf_frmts.h"
|
||||||
|
#include <gdal/ogr_core.h>
|
||||||
|
#include <gdal/ogr_feature.h>
|
||||||
|
#include <gdal/ogr_geometry.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -86,7 +89,7 @@ void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
|
|||||||
|
|
||||||
OGRLayer *poLayer;
|
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 )
|
if( poLayer == NULL )
|
||||||
{
|
{
|
||||||
printf( "Layer creation failed.\n" );
|
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++)
|
for (int j = 0; j < cellmaps.size(); j++)
|
||||||
{
|
{
|
||||||
CellMap* cellmap = &cellmaps[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)
|
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 x_raw = i%cellmap->width;
|
||||||
int y_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);
|
auto [x, y] = local_to_projected(cellmap->geotransform, x_raw, y_raw);
|
||||||
|
|
||||||
|
|
||||||
pt.setX( x );
|
geometry->setPoint( i, x, y );
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 );
|
GDALClose( poDS );
|
||||||
|
Loading…
Reference in New Issue
Block a user