mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2026-03-17 17:34:03 +00:00
Compare commits
32 Commits
e457adf244
...
drawing-li
| Author | SHA1 | Date | |
|---|---|---|---|
| 9300fa729c | |||
| 62d62987d3 | |||
| 5845ae6693 | |||
| 47d0e29868 | |||
| 43f8b78830 | |||
| 08255875c1 | |||
| ec0a31db5d | |||
|
|
32a0b18f8e | ||
|
|
ab96f9477e | ||
| 790cf44f8b | |||
| df7cac1095 | |||
| 93fcbc6a39 | |||
| 95649f005b | |||
| 1ec3e8c778 | |||
| c535eec958 | |||
| 4f709d3b07 | |||
| 4cd4f773bf | |||
| 9d8df3256d | |||
|
|
77467594bd | ||
| 0188b9e29d | |||
| b800ceaf98 | |||
| 1dcfb0e737 | |||
|
|
228945a767 | ||
|
|
d046e18c43 | ||
|
|
33dd409c43 | ||
|
|
5cd5627bb7 | ||
| 29a7ddb083 | |||
| 98a312094e | |||
| 882764a13d | |||
| f962a40ade | |||
| ee0b87c2b3 | |||
| 0485253893 |
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "extern/argh"]
|
||||
path = extern/argh
|
||||
url = https://github.com/adishavit/argh.git
|
||||
@@ -1,15 +1,22 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
project(
|
||||
contour-creator
|
||||
LANGUAGES CXX)
|
||||
|
||||
find_package(GDAL CONFIG REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
src/HeightMap.cpp src/CellMap.cpp src/main.cpp
|
||||
)
|
||||
|
||||
# Argh is a simple argrument parser
|
||||
add_subdirectory(extern/argh)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE argh)
|
||||
|
||||
# Gdal is used for geodata IO
|
||||
find_package(GDAL CONFIG REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE GDAL::GDAL)
|
||||
|
||||
find_package(OpenMP)
|
||||
if(OpenMP_CXX_FOUND)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} GDAL::GDAL)
|
||||
endif()
|
||||
@@ -3,4 +3,4 @@ rm -rf build
|
||||
mkdir build
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug -B build
|
||||
cmake --build build --parallel
|
||||
build/contour-creator 'example_files/crop.tif'
|
||||
build/contour-creator --interval=1 --blur example_files/crop.tif
|
||||
|
||||
BIN
documentation/kurver_ås.png
Normal file
BIN
documentation/kurver_ås.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
3092
documentation/ms_wikipedia.svg
Normal file
3092
documentation/ms_wikipedia.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 88 KiB |
@@ -5,16 +5,31 @@ author:
|
||||
- Trygve og Esther
|
||||
|
||||
---
|
||||
# What are contours
|
||||
|
||||
# Output of our program
|
||||
pretty pictures
|
||||
# Output of our program:
|
||||

|
||||
|
||||
# Marching squares
|
||||

|
||||
|
||||
# The logical flow of our program
|
||||
flowchart
|
||||
|
||||
# GDAL
|
||||
What is it?
|
||||
```cpp
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
const char* filepath = argv[1];
|
||||
HeightMap map(filepath);
|
||||
map.blur(0.8)
|
||||
auto lines = create_lines(&map, 5);
|
||||
write_output_file(cellmaps, "out.geojson", &map);
|
||||
}
|
||||
```
|
||||
|
||||
# Performance
|
||||
show the benchmarks
|
||||
| | Time |
|
||||
|--------------------|--------------------|
|
||||
| 12 threads | 41s |
|
||||
| 1 thread | 116s |
|
||||
|
||||
|
||||
# Problems we encountered
|
||||
|
||||
|
||||
1
extern/argh
vendored
Submodule
1
extern/argh
vendored
Submodule
Submodule extern/argh added at 431bf323ac
@@ -4,13 +4,13 @@
|
||||
#include "contour_creator.hh"
|
||||
|
||||
|
||||
CellMap::CellMap(int width, int height, uint8_t* cells, OGRSpatialReference reference_system)
|
||||
CellMap::CellMap(int width, int height, uint8_t* cells, OGRSpatialReference reference_system, double* geotransform)
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->cells = cells;
|
||||
this->reference_system = reference_system;
|
||||
|
||||
this->geotransform = geotransform;
|
||||
}
|
||||
int CellMap::get_cell(int x, int y)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <gdal/cpl_conv.h>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <omp.h>
|
||||
#include <gdal/gdal.h>
|
||||
#include "gdal/gdal_priv.h"
|
||||
#include <gdal/gdal_frmts.h>
|
||||
@@ -28,7 +29,11 @@ HeightMap::HeightMap(const char* filepath)
|
||||
this->height = band->GetYSize();
|
||||
this->min = band->GetMinimum();
|
||||
this->max = band-> GetMaximum();
|
||||
//https://gdal.org/api/gdaldataset_cpp.html#_CPPv4N11GDALDataset15GetGeoTransformEPd
|
||||
this->geotransform = (double *) CPLMalloc(sizeof(double)*6);
|
||||
this->reference_system = *(file->GetSpatialRef());
|
||||
|
||||
file->GetGeoTransform(this->geotransform);
|
||||
|
||||
this->data = (float *) CPLMalloc(sizeof(float)*width*height);
|
||||
CPLErr error = band->RasterIO( GF_Read, 0, 0, width, height,
|
||||
@@ -43,4 +48,46 @@ float HeightMap::get_pixel(int x, int y)
|
||||
int offset = ((this->width * y) + x);
|
||||
//std::cout << " offset: " << offset << " " << x << ","<< y;
|
||||
return *(this->data + offset);
|
||||
}
|
||||
|
||||
void HeightMap::blur(float standard_deviation)
|
||||
{
|
||||
// standard_deviation does not do anything yet. This is currently a simple box blur
|
||||
int kernel_height = 5;
|
||||
int kernel_width = 5;
|
||||
int kernel_size = kernel_height*kernel_width;
|
||||
float* kernel = (float*) CPLMalloc(sizeof(float)*kernel_size);
|
||||
for (int i=0; i<kernel_size; i++)
|
||||
{
|
||||
*(kernel + i) = 1.0;
|
||||
}
|
||||
|
||||
float* blurred = (float *) CPLMalloc(sizeof(float)*this->width*this->height);
|
||||
#pragma omp parallel
|
||||
{
|
||||
#pragma omp for
|
||||
for (int i = 0; i < this->height * this->width; i++)
|
||||
{
|
||||
float blurred_pixel = 0;
|
||||
for (int j = 0; j < kernel_size; j++)
|
||||
{
|
||||
int x = j%kernel_width - kernel_width/2 + i%this->width;
|
||||
int y = j/kernel_width - kernel_height/2 + i/this->width;
|
||||
if (x<0 || x>=this->width)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (y<0 || y>=this->height)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
blurred_pixel += this->get_pixel(x, y);
|
||||
}
|
||||
*(blurred + i) = blurred_pixel/float(kernel_size);
|
||||
}
|
||||
}
|
||||
free(this->data);
|
||||
this->data = blurred;
|
||||
blurred = nullptr;
|
||||
}
|
||||
@@ -9,6 +9,8 @@ class HeightMap
|
||||
{
|
||||
public:
|
||||
float* data;
|
||||
double* geotransform; //!< Six double buffer for storing the affine transformations
|
||||
// https://gdal.org/api/gdaldataset_cpp.html#_CPPv4N11GDALDataset15GetGeoTransformEPd
|
||||
int width; //!< width of image in pixels
|
||||
int height; //!< height of image in pixels
|
||||
float min; //!< Minimum value in image
|
||||
@@ -17,6 +19,7 @@ class HeightMap
|
||||
|
||||
HeightMap(const char* filepath);
|
||||
float get_pixel(int x,int y);
|
||||
void blur(float standard_deviation);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -26,10 +29,24 @@ class CellMap
|
||||
{
|
||||
public:
|
||||
uint8_t* cells; //!< pointer to the first cell in the array. uint8_t is a 8 bit unsigned integer
|
||||
double* geotransform; //!< Six double buffer for storing the affine transformations
|
||||
int width; //!< width of image in cells
|
||||
int height; //!< height of image in cells
|
||||
OGRSpatialReference reference_system;
|
||||
|
||||
CellMap(int width, int height, uint8_t* cells, OGRSpatialReference reference_system);
|
||||
CellMap(int width, int height, uint8_t* cells, OGRSpatialReference reference_system, double* geotransform);
|
||||
int get_cell(int x,int y);
|
||||
};
|
||||
};
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
int x;
|
||||
int y;
|
||||
int mscase;
|
||||
bool allocated = false;
|
||||
Point(int x, int y, int mscase){
|
||||
this -> x = x;
|
||||
this -> y = y;
|
||||
this -> mscase = mscase;
|
||||
};
|
||||
};
|
||||
|
||||
320
src/main.cpp
320
src/main.cpp
@@ -1,59 +1,191 @@
|
||||
#include "contour_creator.hh"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#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 <sys/types.h>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <gdal/gdal.h>
|
||||
#include "gdal/gdal_priv.h"
|
||||
#include <gdal/gdal_frmts.h>
|
||||
#include <omp.h>
|
||||
#include "argh.h"
|
||||
|
||||
CellMap produce_cellmap(HeightMap* heightmap, float z)
|
||||
std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
|
||||
{
|
||||
int length = (heightmap->width-1)*(heightmap->height-1);
|
||||
int length = (heightmap->width-1)*(heightmap->height-1); // Defining length of vector
|
||||
uint8_t *cells = (uint8_t *) CPLMalloc(sizeof(uint8_t)*length);
|
||||
std::vector<Point> points; // Initiating a vector of points
|
||||
for (int i = 0; i<length; i++) {
|
||||
int y = i/(heightmap->width-1);
|
||||
int x = i%(heightmap->width-1);
|
||||
uint8_t result = (heightmap->get_pixel(x,y)>z) +
|
||||
(heightmap->get_pixel(x+1,y)>z)*2 +
|
||||
(heightmap->get_pixel(x+1,y+1)>z)*4 +
|
||||
(heightmap->get_pixel(x,y+1)>z)*8;
|
||||
*(cells + i) = result;
|
||||
uint8_t result = (heightmap->get_pixel(x,y)>z)*8 +
|
||||
(heightmap->get_pixel(x+1,y)>z)*4 +
|
||||
(heightmap->get_pixel(x+1,y+1)>z)*2 +
|
||||
(heightmap->get_pixel(x,y+1)>z);
|
||||
if (result != 0 and result != 15 ) {
|
||||
points.push_back(Point(x, y, result));
|
||||
};
|
||||
}
|
||||
|
||||
return CellMap(heightmap->width-1, heightmap->height-1, cells, heightmap->reference_system);
|
||||
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
std::vector<CellMap> vector_cellmap(HeightMap* heightmap, int interval)
|
||||
bool is_in(int value, std::array<int, 8> array)
|
||||
{
|
||||
return std::binary_search(array.begin(), array.end(), value);
|
||||
}
|
||||
|
||||
std::vector<std::vector<Point>> create_lines(HeightMap* heightmap, int interval)
|
||||
{
|
||||
int num_contours = (heightmap->max - heightmap->min)/interval;
|
||||
std::vector<CellMap> vector_contours;
|
||||
omp_set_num_threads(12);
|
||||
std::vector<std::vector<Point>> vector_contours;
|
||||
|
||||
std::array<int,8> north{4, 5,6,7,8,9,10,11};
|
||||
std::array<int,8> south{1,2,5,6,9,10,13,14};
|
||||
std::array<int,8> east{2,3,4,5,10,11,12,13};
|
||||
std::array<int,8> west{1,3,5,7,8,10,12,14};
|
||||
|
||||
#pragma omp parallel
|
||||
{
|
||||
std::vector<CellMap> vec_private;
|
||||
std::vector<std::vector<Point>> vec_private;
|
||||
#pragma omp for
|
||||
for (int i = 1; i <= num_contours; i++)
|
||||
{
|
||||
vec_private.push_back(produce_cellmap(heightmap, heightmap->min + interval*i));
|
||||
auto points = produce_cellmap(heightmap, heightmap->min + interval*i);
|
||||
std::vector<Point> line;
|
||||
int x;
|
||||
int y;
|
||||
int points_allocated = 0;
|
||||
x = points[0].x;
|
||||
y = points[0].y;
|
||||
int current_case = points[0].mscase;
|
||||
points[0].allocated = true;
|
||||
line.push_back(points[0]);
|
||||
for (int j = 0; j < points.size(); j++){
|
||||
for (int k = 0; k < points.size(); k++){
|
||||
Point* candidate = &points[k];
|
||||
if (!candidate->allocated) {
|
||||
if (candidate->x == x +1 && candidate->y == y /*&& is_in(current_case, east)*/) {
|
||||
candidate->allocated = true;
|
||||
x = candidate->x;
|
||||
y = candidate->y;
|
||||
current_case = candidate->mscase;
|
||||
line.push_back(*candidate);
|
||||
points_allocated++;
|
||||
break;
|
||||
}
|
||||
else if (candidate->x == x -1 && candidate->y == y /*&& is_in(current_case, west)*/) {
|
||||
x = candidate->x;
|
||||
y = candidate->y;
|
||||
current_case = candidate->mscase;
|
||||
candidate->allocated = true;
|
||||
line.push_back(*candidate);
|
||||
points_allocated++;
|
||||
break;
|
||||
}
|
||||
else if (candidate->x == x && candidate->y == y + 1 /*&& is_in(current_case, north)*/) {
|
||||
x = candidate->x;
|
||||
y = candidate->y;
|
||||
current_case = candidate->mscase;
|
||||
candidate->allocated = true;
|
||||
line.push_back(*candidate);
|
||||
points_allocated++;
|
||||
break;
|
||||
}
|
||||
else if (candidate->x == x && candidate->y == y - 1 /*&& is_in(current_case, south)*/) {
|
||||
x = candidate->x;
|
||||
y = candidate->y;
|
||||
current_case = candidate->mscase;
|
||||
candidate->allocated = true;
|
||||
line.push_back(*candidate);
|
||||
points_allocated++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (j > points_allocated)
|
||||
{
|
||||
vec_private.push_back(line);
|
||||
line.clear();
|
||||
//std::cout << points.size() << " ";
|
||||
for (int k = 0; k < points.size(); k++){
|
||||
Point* candidate = &points[k];
|
||||
if (!candidate->allocated)
|
||||
{
|
||||
line.push_back(*candidate);
|
||||
candidate->allocated = true;
|
||||
x = candidate->x;
|
||||
y = candidate->y;
|
||||
current_case = candidate->mscase;
|
||||
points_allocated++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#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());
|
||||
}
|
||||
return vector_contours;
|
||||
}
|
||||
|
||||
void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
|
||||
std::tuple<double, double> local_to_projected(double* geotransform, int x, int y)
|
||||
{
|
||||
return {
|
||||
geotransform[1] * x + geotransform[2] * y +
|
||||
geotransform[1] * 0.5 + geotransform[2] * 0.5 + geotransform[0],
|
||||
geotransform[4] * x + geotransform[5] * y +
|
||||
geotransform[4] * 0.5 + geotransform[5] * 0.5 + geotransform[3]
|
||||
};
|
||||
}
|
||||
|
||||
constexpr std::tuple<double, double, double, double> marching_squares_lookup(int mcase)
|
||||
{
|
||||
switch (mcase) {
|
||||
case 1:
|
||||
return {0, 0.5, 0.5, 0};
|
||||
case 14:
|
||||
return {0.5, 0, 0, 0.5};
|
||||
case 2:
|
||||
return {0.5, 0, 1, 0.5};
|
||||
case 13:
|
||||
return {1, 0.5, 0.5, 0};
|
||||
case 3:
|
||||
return {0, 0.5, 1, 0.5};
|
||||
case 12:
|
||||
return {1, 0.5, 0, 0.5};
|
||||
case 4:
|
||||
return {0.5, 1, 1, 0.5};
|
||||
case 11:
|
||||
return {1, 0.5, 0.5, 1};
|
||||
case 5:
|
||||
case 10:
|
||||
return {0, 0, 0, 0}; //FIXME
|
||||
case 6:
|
||||
return {0.5, 1, 0.5, 0};
|
||||
case 9:
|
||||
return {0.5, 0, 0.5, 1};
|
||||
case 7:
|
||||
return {0, 0.5, 0.5, 1};
|
||||
case 8:
|
||||
return {0.5, 0.5, 0, 0.5};
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
void write_output_file(std::vector<std::vector<Point>> all_points, const char *filepath, HeightMap* heightmap)
|
||||
{
|
||||
|
||||
const char *pszDriverName = "ESRI Shapefile";
|
||||
const char *pszDriverName = "GeoJSON";
|
||||
GDALDriver *poDriver;
|
||||
|
||||
GDALAllRegister();
|
||||
@@ -76,7 +208,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", &heightmap->reference_system, wkbLineString, NULL );
|
||||
if( poLayer == NULL )
|
||||
{
|
||||
printf( "Layer creation failed.\n" );
|
||||
@@ -92,81 +224,101 @@ void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
|
||||
printf( "Creating Name field failed.\n" );
|
||||
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];
|
||||
for (int i = 0; i<cellmap->height*cellmap->width; i++) {
|
||||
if (*(cellmap->cells + i) != 0 && *(cellmap->cells + i) != 15)
|
||||
OGRFeature *feature;
|
||||
OGRLineString *geometry = new OGRLineString();
|
||||
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
|
||||
feature->SetField( "Name", j );
|
||||
|
||||
std::vector<Point> points = all_points[j];
|
||||
|
||||
bool left_to_right = true;
|
||||
|
||||
if ((points[0].y - points[1].y) < 0)
|
||||
left_to_right = true;
|
||||
else
|
||||
left_to_right = false;
|
||||
|
||||
for (int k = 0; k < points.size(); k++)
|
||||
{
|
||||
bool left_to_right = true;
|
||||
|
||||
if ((points[k].x - points[k-1].x) < 0)
|
||||
left_to_right = false;
|
||||
bool top_to_bottom = true;
|
||||
if ((points[k].y - points[k-1].y) < 0)
|
||||
left_to_right = false;
|
||||
|
||||
|
||||
|
||||
int x_raw = points[k].x;
|
||||
int y_raw = points[k].y;
|
||||
auto [x, y] = local_to_projected(heightmap->geotransform, x_raw, y_raw);
|
||||
|
||||
auto [x1, y1, x2, y2] = marching_squares_lookup(points[k].mscase);
|
||||
|
||||
if (left_to_right or !top_to_bottom)
|
||||
{
|
||||
int x_int = i%cellmap->width;
|
||||
int y_int = cellmap->height*cellmap->width - i/cellmap->width;
|
||||
double x = double(x_int);
|
||||
double y = double(y_int);
|
||||
|
||||
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;
|
||||
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 );
|
||||
geometry->setPoint(geometry->getNumPoints(),x + (x1/6) ,y + (y1/6));
|
||||
geometry->setPoint(geometry->getNumPoints(),x + (x2/6) ,y + (y2/6));
|
||||
}
|
||||
else {
|
||||
geometry->setPoint(geometry->getNumPoints(),x + (x2/6) ,y + (y2/6));
|
||||
geometry->setPoint(geometry->getNumPoints(),x + (x1/6) ,y + (y1/6));
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
/*
|
||||
OGRDataSourceH datasource = OGR_Dr_CreateDataSource(OGRGetDriverByName("GeoJSON"), "contour.geojson", new char*);
|
||||
OGRSpatialReference reference_system = cellmap->reference_system;
|
||||
OGRLayerH layer = OGR_DS_CreateLayer(datasource, "contour", &reference_system, wkbLineString25D, new char*);
|
||||
|
||||
auto feature = OGR_F_Create(OGR_L_GetLayerDefn(static_cast<OGRLayerH>(layer)));
|
||||
|
||||
OGRGeometryH geometry = OGR_G_CreateGeometry(wkbLineString25D);
|
||||
*/
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
const char* filepath = argv[1];
|
||||
HeightMap map(filepath);
|
||||
|
||||
std::cout << "x: " << map.width << " y: " << map.height << "\n";
|
||||
std::cout << "max: " << map.max << " min: " << map.min << "\n";
|
||||
|
||||
auto cellmap = produce_cellmap(&map, 40);
|
||||
/*
|
||||
for (int y = 0; y < cellmap.height; y++)
|
||||
argh::parser cmdl(argv);
|
||||
|
||||
if (cmdl[{ "-h", "--help" }])
|
||||
{
|
||||
for (int x = 0; x < cellmap.width; x++)
|
||||
{
|
||||
if (cellmap.get_cell(x, y) && cellmap.get_cell(x, y)!=15) {
|
||||
std::cout << x << ","<< y << "=" << cellmap.get_cell(x, y) << " ";
|
||||
}
|
||||
}
|
||||
//std::cout << "\n";
|
||||
std::cout << "Usage:\n"
|
||||
<< "contour_creator [OPTIONS] <input_file>\n"
|
||||
<< "-o; --output <FILENAME.geojson> - File to write output to (Default: contours.geojson)\n"
|
||||
<< "-i; --interval <int> - Set the interval between contours (Default: 5)\n"
|
||||
<< "-b; --blur - Blur the image\n"
|
||||
<< "--stats - Print statistical information about the heightmap\n";
|
||||
exit(0);
|
||||
}
|
||||
*/
|
||||
int interval;
|
||||
cmdl({"-i", "--interval"}, 5) >> interval;
|
||||
if (interval <= 0)
|
||||
std::cerr << "Interval must be valid positive integer!" << "\n";
|
||||
|
||||
auto cellmaps = vector_cellmap(&map, 5);
|
||||
write_output_file(cellmaps, "out.shp");
|
||||
std::string output_file;
|
||||
cmdl({"-o", "--output"}, "contours.geojson") >> output_file;
|
||||
|
||||
std::string input_file;
|
||||
cmdl(1) >> input_file;
|
||||
|
||||
|
||||
HeightMap map(input_file.c_str());
|
||||
if (cmdl[{"-b", "--blur"}])
|
||||
map.blur(0.8);
|
||||
auto lines = create_lines(&map, interval);
|
||||
write_output_file(lines, output_file.c_str(), &map);
|
||||
std::cout << "Contours written to " << output_file << " 🗺️\n";
|
||||
}
|
||||
Reference in New Issue
Block a user