Skip to content

Commit

Permalink
update sosi driver, change makefiles to include sosi. --> automake wi…
Browse files Browse the repository at this point in the history
…ll overwrite these changes currently, but configure && make && make install should work
  • Loading branch information
Thomas Hirsch committed Apr 10, 2013
1 parent 32b7457 commit 321bc97
Show file tree
Hide file tree
Showing 19 changed files with 28,970 additions and 67 deletions.
3 changes: 2 additions & 1 deletion gdal/ogr/ogrsf_frmts/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SUBDIRS-yes := \
mitab ntf gpx rec s57 sdts shape tiger vrt \
geoconcept xplane georss gtm dxf pgdump gpsbabel \
sua openair pds htf aeronavfaa edigeo svg idrisi \
arcgen segukooa segy
arcgen segukooa segy sosi

SUBDIRS-$(HAVE_DODS) += dods
SUBDIRS-$(HAVE_DWGDIRECT) += dxfdwg
Expand Down Expand Up @@ -36,6 +36,7 @@ SUBDIRS-$(HAVE_EXPAT) += ods
SUBDIRS-$(HAVE_EXPAT) += xlsx
SUBDIRS-$(CURL_SETTING) += elastic
SUBDIRS-$(HAVE_SQLITE) += osm
SUBDIRS-$(HAVE_SOSI) += sosi

ifeq ($(PCIDSK_SETTING),internal)
SUBDIRS-yes += pcidsk
Expand Down
5 changes: 5 additions & 0 deletions gdal/ogr/ogrsf_frmts/generic/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ BASEFORMATS = \
-DIDRISI_ENABLED \
-DARCGEN_ENABLED \
-DSEGUKOOA_ENABLED \
-DSOSI_ENABLED \
-DSEGY_ENABLED

CXXFLAGS := $(CXXFLAGS) -DINST_DATA=\"$(INST_DATA)\" $(BASEFORMATS)
Expand Down Expand Up @@ -135,6 +136,10 @@ ifeq ($(HAVE_PANORAMA),yes)
CXXFLAGS := $(CXXFLAGS) -DPANORAMA_ENABLED
endif

ifeq ($(HAVE_SOSI),yes)
CXXFLAGS := $(CXXFLAGS) -DSOSI_ENABLED
endif

ifeq ($(HAVE_SQLITE),yes)
CXXFLAGS := $(CXXFLAGS) -DVFK_ENABLED
endif
Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogrsf_frmts/generic/ogrregisterall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void OGRRegisterAll()
RegisterOGRWFS();
#endif
#ifdef SOSI_ENABLED
RegisterOGRSOSI();
RegisterOGRSOSI();
#endif
#ifdef HTF_ENABLED
RegisterOGRHTF();
Expand Down
15 changes: 15 additions & 0 deletions gdal/ogr/ogrsf_frmts/sosi/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


include ../../../GDALmake.opt

OBJ = ogrsosidriver.o ogrsosidatasource.o ogrsosilayer.o ogrsosidatatypes.o

CPPFLAGS :=-DLINUX -DUNIX -I.. -I../.. $(GDAL_INCLUDE) $(CPPFLAGS)

default: $(O_OBJ:.o=.$(OBJ_EXT))

clean:
rm -f *.o $(O_OBJ)

$(O_OBJ): ogr_sosi.h

2 changes: 1 addition & 1 deletion gdal/ogr/ogrsf_frmts/sosi/fyba_melding.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* $Id$
* $Id: fyba_melding.cpp 20487 2010-08-29 21:42:53Z rouault $
*
* Project: FYBA Callbacks
* Purpose: Needed by FYBA - however we do not want to display most messages
Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogrsf_frmts/sosi/makefile.vc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

OBJ = ogrsosidriver.obj ogrsosidatasource.obj ogrsosilayer.obj fyba_melding.obj \

EXTRAFLAGS = -I.. -I..\.. -I$(SOSI_INC_DIR)
EXTRAFLAGS = -I.. -I..\..

GDAL_ROOT = ..\..\..

Expand Down
56 changes: 55 additions & 1 deletion gdal/ogr/ogrsf_frmts/sosi/ogr_sosi.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* $Id$
* $Id: ogr_sosi.h 21065 2010-11-05 18:47:30Z rouault $
*
* Project: SOSI Translator
* Purpose: Implements OGRSOSIDriver.
Expand Down Expand Up @@ -34,6 +34,9 @@
#include "fyba.h"
#include <map>

/* interpolation of arcs(BUEP) creates # points for a full circle */
#define ARC_INTERPOLATION_FULL_CIRCLE 36.0

typedef std::map<CPLString, CPLString> S2S;
typedef std::map<CPLString, unsigned int> S2I;

Expand Down Expand Up @@ -110,6 +113,7 @@ class OGRSOSIDataSource : public OGRDataSource {
void buildOGRPoint(long nSerial);
void buildOGRLineString(int nNumCoo, long nSerial);
void buildOGRMultiPoint(int nNumCoo, long nSerial);
void buildOGRLineStringFromArc(long nSerial);

public:

Expand Down Expand Up @@ -143,4 +147,54 @@ class OGRSOSIDataSource : public OGRDataSource {
int TestCapability( const char * );
};

/************************************************************************
* OGRSOSIDataTypes *
* OGRSOSIDataTypes provides the correct data types for some of the *
* most common SOSI elements. *
************************************************************************/

class OGRSOSISimpleDataType {
const char *pszName;
OGRFieldType nType;

public:
OGRSOSISimpleDataType ();
OGRSOSISimpleDataType (const char *pszName, OGRFieldType nType);
~OGRSOSISimpleDataType();

void setType (const char *pszName, OGRFieldType nType);
const char *GetName() {
return pszName;
};
OGRFieldType GetType() {
return nType;
};

};

class OGRSOSIDataType {
OGRSOSISimpleDataType* poElements;
int nElementCount;
public:
OGRSOSIDataType (int nSize);
~OGRSOSIDataType();

void setElement(int nIndex, const char *name, OGRFieldType type);
OGRSOSISimpleDataType* getElements() {
return poElements;
};
int getElementCount() {
return nElementCount;
};
};

typedef std::map<CPLString, OGRSOSIDataType> C2F;

void SOSIInitTypes();
OGRSOSIDataType* SOSIGetType(CPLString name);
int SOSITypeToInt(char* value);
float SOSITypeToReal(char* value);
void SOSITypeToDate(char* value, int* date);
void SOSITypeToDateTime(char* value, int* date);

#endif /* _OGR_SOSI_H_INCLUDED */
131 changes: 114 additions & 17 deletions gdal/ogr/ogrsf_frmts/sosi/ogrsosidatasource.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* $Id$
* $Id: ogrsosidatasource.cpp 21065 2010-11-05 18:47:30Z rouault $
*
* Project: SOSI Data Source
* Purpose: Provide SOSI Data to OGR.
Expand Down Expand Up @@ -27,8 +27,11 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/

#define _USE_MATH_DEFINES

#include "ogr_sosi.h"
#include <map>
#include <math.h>

/* This is the most common encoding for SOSI files. Let's at least try if
* it is supported, or generate a meaningful error message. */
Expand Down Expand Up @@ -148,6 +151,8 @@ OGRSOSIDataSource::OGRSOSIDataSource() {
poCurveHeaders = NULL;

pszEncoding = CPL_ENC_UTF8;

SOSIInitTypes();
}

/************************************************************************/
Expand Down Expand Up @@ -192,17 +197,20 @@ OGRSOSIDataSource::~OGRSOSIDataSource() {
if (pszName != NULL) CPLFree(pszName);
}

OGRFeatureDefn *defineLayer(char *szName, OGRwkbGeometryType szType, S2I *poHeaders) {
OGRFeatureDefn *defineLayer(const char *szName, OGRwkbGeometryType szType, S2I *poHeaders, S2I **ppoHeadersNew) {
OGRFeatureDefn *poFeatureDefn = new OGRFeatureDefn( szName );
poFeatureDefn->SetGeomType( szType );
S2I* poHeadersNew = *ppoHeadersNew;

for (unsigned int n=0; n<poHeaders->size(); n++) { /* adding headers in the correct order again */
for (S2I::iterator i=poHeaders->begin(); i!=poHeaders->end(); i++) {
if (n==i->second) {
OGRFieldDefn oFieldTemplate( i->first.c_str(), OFTString );
poFeatureDefn->AddFieldDefn( &oFieldTemplate );
}
}
for (S2I::iterator i=poHeaders->begin(); i!=poHeaders->end(); i++) {
OGRSOSIDataType* poType = SOSIGetType(i->first);
OGRSOSISimpleDataType* poElements = poType->getElements();
for (int k=0; k<poType->getElementCount(); k++) {
if (strcmp(poElements[k].GetName(),"")==0) continue;
OGRFieldDefn oFieldTemplate( poElements[k].GetName(), poElements[k].GetType() );
(*poHeadersNew)[CPLString(poElements[k].GetName())] = poFeatureDefn->GetFieldCount();
poFeatureDefn->AddFieldDefn( &oFieldTemplate );
}
}
return poFeatureDefn;
}
Expand Down Expand Up @@ -321,14 +329,17 @@ int OGRSOSIDataSource::Open( const char *pszFilename, int bUpdate ) {
}
break;
}
case L_KURVE: {
case L_KURVE:
case L_LINJE:
case L_BUEP: { /* FIXME: maybe not use the same headers for both */
if (poCurveHeaders->find(osKey) == poCurveHeaders->end()) {
iH = poCurveHeaders->size();
(*poCurveHeaders)[osKey] = iH;
}
break;
}
case L_PUNKT: {
case L_PUNKT:
case L_SYMBOL: {
if (poPointHeaders->find(osKey) == poPointHeaders->end()) {
iH = poPointHeaders->size();
(*poPointHeaders)[osKey] = iH;
Expand All @@ -349,7 +360,8 @@ int OGRSOSIDataSource::Open( const char *pszFilename, int bUpdate ) {

/* Feature-specific tasks */
switch (nName) {
case L_PUNKT: {
case L_PUNKT:
case L_SYMBOL: {
/* Pre-build a point feature. Activate point layer. */
bPointLayer = TRUE;
buildOGRPoint(oNextSerial.lNr);
Expand All @@ -361,12 +373,19 @@ int OGRSOSIDataSource::Open( const char *pszFilename, int bUpdate ) {
/* cannot build geometries that reference others yet */
break;
}
case L_KURVE: {
case L_KURVE:
case L_LINJE: {
/* Pre-build a line feature. Activate line/curve layer. */
bCurveLayer = TRUE;
buildOGRLineString(nNumCoo, oNextSerial.lNr);
break;
}
case L_BUEP: {
/* Pre-build a line feature as interpolation from an arc. Activate line/curve layer. */
bCurveLayer = TRUE;
buildOGRLineStringFromArc(oNextSerial.lNr);
break;
}
case L_TEKST: {
/* Pre-build a text line contour feature. Activate text layer. */
/* Todo: observe only points 2ff if more than one point is given for follow mode */
Expand Down Expand Up @@ -431,31 +450,43 @@ int OGRSOSIDataSource::Open( const char *pszFilename, int bUpdate ) {
* and adding every SOSI header encountered in the file as field. */
S2I::iterator i;
if (bPolyLayer) {
OGRFeatureDefn *poFeatureDefn = defineLayer("polygons", wkbPolygon, poPolyHeaders);
S2I * poHeadersNew = new S2I();
OGRFeatureDefn *poFeatureDefn = defineLayer("polygons", wkbPolygon, poPolyHeaders, &poHeadersNew);
delete poPolyHeaders;
poPolyHeaders = poHeadersNew;
poFeatureDefn->Reference();
papoLayers[--nLayers] = new OGRSOSILayer( this, poFeatureDefn, poFileadm, poPolyHeaders );
} else {
delete poPolyHeaders;
poPolyHeaders = NULL;
}
if (bCurveLayer) {
OGRFeatureDefn *poFeatureDefn = defineLayer("lines", wkbLineString, poCurveHeaders);
S2I * poHeadersNew = new S2I();
OGRFeatureDefn *poFeatureDefn = defineLayer("lines", wkbLineString, poCurveHeaders, &poHeadersNew);
delete poCurveHeaders;
poCurveHeaders = poHeadersNew;
poFeatureDefn->Reference();
papoLayers[--nLayers] = new OGRSOSILayer( this, poFeatureDefn, poFileadm, poCurveHeaders );
} else {
delete poCurveHeaders;
poCurveHeaders = NULL;
}
if (bPointLayer) {
OGRFeatureDefn *poFeatureDefn = defineLayer("points", wkbPoint, poPointHeaders);
S2I * poHeadersNew = new S2I();
OGRFeatureDefn *poFeatureDefn = defineLayer("points", wkbPoint, poPointHeaders, &poHeadersNew);
delete poPointHeaders;
poPointHeaders = poHeadersNew;
poFeatureDefn->Reference();
papoLayers[--nLayers] = new OGRSOSILayer( this, poFeatureDefn, poFileadm, poPointHeaders );
} else {
delete poPointHeaders;
poPointHeaders = NULL;
}
if (bTextLayer) {
OGRFeatureDefn *poFeatureDefn = defineLayer("text", wkbMultiPoint, poTextHeaders);
S2I * poHeadersNew = new S2I();
OGRFeatureDefn *poFeatureDefn = defineLayer("text", wkbMultiPoint, poTextHeaders, &poHeadersNew);
delete poTextHeaders;
poTextHeaders = poHeadersNew;
poFeatureDefn->Reference();
papoLayers[--nLayers] = new OGRSOSILayer( this, poFeatureDefn, poFileadm, poTextHeaders );
} else {
Expand Down Expand Up @@ -588,6 +619,72 @@ void OGRSOSIDataSource::buildOGRLineString(int nNumCoo, long iSerial) {
}
papoBuiltGeometries[iSerial] = poLS;
}

double sqr(double x) { return x * x; }

void OGRSOSIDataSource::buildOGRLineStringFromArc(long iSerial) {
if (papoBuiltGeometries[iSerial] != NULL) {
return;
}

OGRLineString *poLS = new OGRLineString();

/* fetch reference points on circle (easting, northing) */
double e1 = 0, e2 = 0, e3 = 0;
double n1 = 0, n2 = 0, n3 = 0;
LC_GetTK(1, &e1, &n1);
LC_GetTK(2, &e2, &n2);
LC_GetTK(3, &e3, &n3);

/* helper constants */
double p12 = (e1 * e1 - e2 * e2 + n1 * n1 - n2 * n2) / 2;
double p13 = (e1 * e1 - e3 * e3 + n1 * n1 - n3 * n3) / 2;

double dE12 = e1 - e2;
double dE13 = e1 - e3;
double dN12 = n1 - n2;
double dN13 = n1 - n3;

/* center of the circle */
double cE = (dN13 * p12 - dN12 * p13) / (dE12 * dN13 - dN12 * dE13) ;
double cN = (dE13 * p12 - dE12 * p13) / (dN12 * dE13 - dE12 * dN13) ;

/* radius of the circle */
double r = sqrt(sqr(e1 - cE) + sqr(n1 - cN));

/* angles of points A and B (1 and 3) */
double th1 = atan2(n1 - cN, e1 - cE);
double th3 = atan2(n3 - cN, e3 - cE);

/* interpolation step in radians */
double dth = th3 - th1;
if (dth < 0) {dth += 2 * M_PI;}
if (dth > M_PI) {
dth = - 2*M_PI + dth;
}
int npt = (int)(ARC_INTERPOLATION_FULL_CIRCLE * dth / 2*M_PI);
if (npt < 0) npt=-npt;
if (npt < 3) npt=3;
poLS->setNumPoints(npt);
dth = dth / (npt-1);

long i;
double dfEast = 0, dfNorth = 0;

for (i=0; i<npt; i++) {
dfEast = cE + r * cos(th1 + dth * i);
dfNorth = cN + r * sin(th1 + dth * i);
if (dfEast != dfEast) { /* which is a wonderful property of nans */
CPLError( CE_Warning, CPLE_AppDefined,
"Calculated %lf for point %li of %i in curve %li.", dfEast, i, npt, iSerial);
}
poLS->setPoint(i, dfEast, dfNorth);
}
papoBuiltGeometries[iSerial] = poLS;


}

void OGRSOSIDataSource::buildOGRPoint(long iSerial) {
double dfEast = 0, dfNorth = 0;
LC_GetTK(1, &dfEast, &dfNorth);
Expand Down
Loading

0 comments on commit 321bc97

Please sign in to comment.