Skip to content

Commit

Permalink
Don't destroy SRS before layer. (#2463)
Browse files Browse the repository at this point in the history
Close #2461
  • Loading branch information
abellgithub committed Apr 17, 2019
1 parent cafa0b4 commit 069d604
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
30 changes: 9 additions & 21 deletions kernels/private/density/OGR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ OGRGeometryH collectHexagon(hexer::HexInfo const& info,

}

} // unnamed namespace
} // unnamed namespace


OGR::OGR(std::string const& filename, std::string srs, std::string driver,
Expand All @@ -134,39 +134,28 @@ OGR::~OGR()

void OGR::createLayer()
{

OGRSFDriverH driver = OGRGetDriverByName(m_driver.c_str());
if (driver == NULL)
{
throw pdal::pdal_error("OGR Driver was null!");
}

char **papszDSCO = NULL;
if (pdal::FileUtils::fileExists(m_filename))
{
if (FileUtils::fileExists(m_filename))
m_ds = OGR_Dr_Open(driver, m_filename.c_str(), TRUE /*update*/);
}
else
{


m_ds = OGR_Dr_CreateDataSource(driver, m_filename.c_str(), NULL);
if (m_ds == NULL)
{
throw pdal::pdal_error("Data source creation was null!");
}
throw pdal_error("Unable to create output file '" + m_filename +
"' for density output.");
}

pdal::gdal::SpatialRef spatialref(m_srs);
OGRSpatialReferenceH ref = (OGRSpatialReferenceH)spatialref.get();

if (!m_layerName.size())
if (m_layerName.empty())
m_layerName = m_filename;
m_layer = OGR_DS_CreateLayer(m_ds, m_layerName.c_str(), ref, wkbMultiPolygon, NULL);
m_layer = GDALDatasetCreateLayer(m_ds, m_layerName.c_str(), m_srs.get(),
wkbMultiPolygon, NULL);
if (m_layer == NULL)
{
throw pdal::pdal_error("Layer creation was null!");
}
throw pdal_error("Layer creation was null!");

OGRFieldDefnH hFieldDefn;
hFieldDefn = OGR_Fld_Create("ID", OFTInteger);
Expand All @@ -188,10 +177,9 @@ void OGR::createLayer()
throw pdal::pdal_error(oss.str());
}
OGR_Fld_Destroy(hFieldDefn);


}


void OGR::writeBoundary(hexer::HexGrid *grid)
{
OGRGeometryH multi = OGR_G_CreateGeometry(wkbMultiPolygon);
Expand Down
4 changes: 3 additions & 1 deletion kernels/private/density/OGR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

#include <string>

#include <pdal/GDALUtils.hpp>

#include "ogr_api.h"
#include "gdal.h"

Expand All @@ -60,7 +62,7 @@ class OGR
private:
std::string m_filename;
std::string m_driver;
std::string m_srs;
gdal::SpatialRef m_srs;

OGRDataSourceH m_ds;
OGRLayerH m_layer;
Expand Down

0 comments on commit 069d604

Please sign in to comment.