Fixed segfault

This commit is contained in:
Trygve 2024-04-27 17:15:37 +02:00
parent ee0b87c2b3
commit f962a40ade

View File

@ -66,7 +66,7 @@ std::tuple<double, double> local_to_projected(double* geotransform, int x, int y
void write_output_file(std::vector<CellMap> cellmaps, const char *filepath) void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
{ {
const char *pszDriverName = "ESRI Shapefile"; const char *pszDriverName = "GeoJSON";
GDALDriver *poDriver; GDALDriver *poDriver;
GDALAllRegister(); GDALAllRegister();
@ -109,7 +109,7 @@ void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
{ {
CellMap* cellmap = &cellmaps[j]; CellMap* cellmap = &cellmaps[j];
OGRFeature *feature; OGRFeature *feature;
OGRLineString *geometry; OGRLineString *geometry = new OGRLineString();
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() ); feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
feature->SetField( "Name", j ); feature->SetField( "Name", j );
for (int i = 0; i < cellmap->height*cellmap->width; i++) for (int i = 0; i < cellmap->height*cellmap->width; i++)
@ -118,15 +118,9 @@ void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
{ {
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);
//std::cout << x << ", " << y << " ";
geometry->setPoint( geometry->getNumPoints(), x, y );
geometry->setPoint( i, x, y );
} }
} }
@ -180,5 +174,5 @@ int main(int argc, const char* argv[])
*/ */
auto cellmaps = vector_cellmap(&map, 5); auto cellmaps = vector_cellmap(&map, 5);
write_output_file(cellmaps, "out.shp"); write_output_file(cellmaps, "out.geojson");
} }