[sosi2osm] 02/30: Initial commit

Ruben Undheim rubund-guest at moszumanska.debian.org
Sat Oct 4 13:07:54 UTC 2014


This is an automated email from the git hooks/post-receive script.

rubund-guest pushed a commit to branch upstream
in repository sosi2osm.

commit fdfda7379902c5cca9352296c50a06d86a264c16
Author: Knut Karevoll <gnonthgol at gmail.com>
Date:   Mon Oct 7 00:00:33 2013 +0200

    Initial commit
---
 .gitignore   |   2 +
 Makefile     |  13 ++++++
 sosi.cpp     | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++
 sosi2osm.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sosi2osm.h   |  13 ++++++
 5 files changed, 276 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b3ddb88
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.o
+sosi2osm
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..906337c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+PROGNAME=sosi2osm
+OBJFILES=sosi2osm.o sosi.o
+
+CPPFLAGS = -I /usr/local/include/fyba/ -DLINUX -DUNIX -g
+LDFLAGS = -lfyba -lfygm -lfyut -lproj
+
+all: $(PROGNAME)
+
+clean:
+	$(RM) $(PROGNAME) $(OBJFILES) *~
+
+$(PROGNAME): $(OBJFILES)
+	$(CXX) $^ $(LDFLAGS) -o $@
diff --git a/sosi.cpp b/sosi.cpp
new file mode 100644
index 0000000..e991c96
--- /dev/null
+++ b/sosi.cpp
@@ -0,0 +1,116 @@
+#include "sosi2osm.h"
+
+LC_BASEADM* base = NULL;
+LC_FILADM* fileadm = NULL;
+
+int openSOSI(const char* input_filename) {
+    LC_Init();
+    
+    // Is this a valid file
+    UT_INT64 end = 0;
+    if (HO_TestSOSI(input_filename, &end) == UT_FALSE) {
+        fprintf(stderr, "Not a SOSI file: %s\n", input_filename);
+        return 0;
+    }
+    
+    // Open the file for reading
+    LC_BASEADM* base = LC_OpenBase(LC_BASE);
+    LC_FILADM* fileadm;
+    short status = 0;
+    LC_OpenSos(input_filename, LC_BASE_FRAMGR, LC_GML_IDX, LC_VIS_STATUS, &fileadm, &status);
+    if (status != 0) {
+        fprintf(stderr, "Could not open SOSI file: %s (%d)\n", input_filename, status);
+        return 0;
+    }
+    
+    return 1;
+}
+
+void closeSOSI() {
+    if (fileadm) LC_CloseSos(fileadm, RESET_IDX);
+    if (base) LC_CloseBase(base, RESET_IDX);
+    LC_Close();
+}
+
+LC_BGR group = {NULL, 0};
+
+int nextSOSIObject() {
+    if (group.pFil == NULL) {
+        LC_InitNextBgr(&group);
+    }
+    
+    if (LC_NextBgr(&group, LC_FRAMGR | LC_BAKGR)) {
+        short lines;
+        long coordinates;
+        unsigned short info;
+        LC_RxGr(&group, LES_OPTIMALT, &lines, &coordinates, &info);
+        return 1;
+    }
+    
+    return 0;
+}
+
+short getSOSIType() {
+    short lines;
+    long coordinates;
+    unsigned short info;
+    return LC_GetGrPara(&lines, &coordinates, &info);
+}
+
+long getSOSIId() {
+	return LC_GetSn();
+}
+
+const char* getCoordinateSystem() {
+	unsigned short mask = LC_TR_ALLT;
+    LC_TRANSPAR trans;
+	if (LC_GetTransEx(&mask,&trans) == UT_FALSE) {
+        fprintf(stderr, "TRANSPAR section not found - No reference system information available.");
+        return "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ";
+    }
+    
+    switch (trans.sKoordsys) {
+        /* NGO 1984 Axis I-VIII */
+        case 1: return "+proj=tmerc +lat_0=58 +lon_0=-4.666666666666667 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
+        case 2: return "+proj=tmerc +lat_0=58 +lon_0=-2.333333333333333 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
+        case 3: return "+proj=tmerc +lat_0=58 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
+        case 4: return "+proj=tmerc +lat_0=58 +lon_0=2.5 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
+        case 5: return "+proj=tmerc +lat_0=58 +lon_0=6.166666666666667 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
+        case 6: return "+proj=tmerc +lat_0=58 +lon_0=10.16666666666667 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
+        case 7: return "+proj=tmerc +lat_0=58 +lon_0=14.16666666666667 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
+        case 8: return "+proj=tmerc +lat_0=58 +lon_0=18.33333333333333 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
+        /* UTM ZONE 31-36 */
+        case 21: return "+proj=utm +zone=31 +ellps=GRS80 +units=m +no_defs ";
+        case 22: return "+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs ";
+        case 23: return "+proj=utm +zone=33 +ellps=GRS80 +units=m +no_defs ";
+        case 24: return "+proj=utm +zone=34 +ellps=GRS80 +units=m +no_defs ";
+        case 25: return "+proj=utm +zone=35 +ellps=GRS80 +units=m +no_defs ";
+        case 26: return "+proj=utm +zone=36 +ellps=GRS80 +units=m +no_defs ";
+        /* UTM ZONE 31-36 / ED50 */
+        case 31: return "+proj=utm +zone=31 +ellps=intl +units=m +no_defs ";
+        case 32: return "+proj=utm +zone=32 +ellps=intl +units=m +no_defs ";
+        case 33: return "+proj=utm +zone=33 +ellps=intl +units=m +no_defs ";
+        case 34: return "+proj=utm +zone=34 +ellps=intl +units=m +no_defs ";
+        case 35: return "+proj=utm +zone=35 +ellps=intl +units=m +no_defs ";
+        case 36: return "+proj=utm +zone=36 +ellps=intl +units=m +no_defs ";
+        /* WSG84 */
+        case 84: return "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ";
+        default: {
+            fprintf(stderr, "(Yet) unsupported coodinate system in SOSI-file: %i. Defaulting to EPSG:4326.", trans.sKoordsys);
+            return "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ";
+        }
+    }
+}
+
+void getSOSICoord(int i, double* x, double* y) {
+    LC_GetTK(i+1, x, y);
+}
+
+long getSOSICoordsSize() {
+    short lines;
+    long coordinates;
+    unsigned short info;
+    LC_GetGrPara(&lines, &coordinates, &info);
+    return coordinates;
+}
+
diff --git a/sosi2osm.cpp b/sosi2osm.cpp
new file mode 100644
index 0000000..a929fe3
--- /dev/null
+++ b/sosi2osm.cpp
@@ -0,0 +1,132 @@
+#include <stdio.h>
+#include <proj_api.h>
+
+#include "sosi2osm.h"
+
+void usage() {
+    printf("Usage: sosi2osm [sosi file]\n");
+}
+
+projPJ origProj, osmProj;
+void handleHead() {
+    if (!(origProj = pj_init_plus(getCoordinateSystem())) )
+        exit(1);
+    if (!(osmProj = pj_init_plus("+proj=latlong +datum=WGS84")) )
+        exit(1);
+}
+
+void getCoords(long int* size, double** lat, double** lon) {
+    *size = getSOSICoordsSize();
+    double* x = (double*)malloc(sizeof(double) * *size);
+    double* y = (double*)malloc(sizeof(double) * *size);
+    *lat = y;
+    *lon = x;
+    
+    int i;
+    for (i = 0; i < *size; i++) {
+        getSOSICoord(i, x+i, y+i);
+    }
+    
+    pj_transform(origProj, osmProj, *size, 1, x, y, NULL );
+    
+    for (i = 0; i < *size; i++) {
+        x[i] = x[i]*RAD_TO_DEG;
+        y[i] = y[i]*RAD_TO_DEG;
+    }
+}
+
+long nodeId = -1;
+long createNode(double lat, double lon) {
+    printf("<node id=\"%ld\" lat=\"%.7f\" lon=\"%.7f\" visible=\"true\"/>\n", nodeId, lat, lon);
+    return nodeId--;
+}
+
+void outputTags() {
+    
+}
+
+void outputNode() {
+    long int size;
+    double *lat, *lon;
+    getCoords(&size, &lat, &lon);
+    
+    for (int i = 0; i < size; i++) {
+        printf("<node id=\"%ld\" lat=\"%.7f\" lon=\"%.7f\" visible=\"true\">\n", nodeId--, lat[i], lon[i]);
+        outputTags();
+        printf("</node>\n");
+    }
+    
+    free(lat);
+    free(lon);
+}
+
+void outputWay() {
+    long int size;
+    double *lat, *lon;
+    getCoords(&size, &lat, &lon);
+    long* nd = (long*)malloc(sizeof(long) * size);
+    
+    for (int i = 0; i < size; i++) {
+        nd[i] = createNode(lat[i], lon[i]);
+    }
+    
+    printf("<way id=\"%ld\" visible=\"true\">", -getSOSIId());
+    outputTags();
+    
+    for (int i = 0; i < size; i++) {
+        printf("<nd ref=\"%ld\" />", nd[i]);
+    }
+    
+    printf("</way>\n");
+    
+    free(lat);
+    free(lon);
+}
+
+void outputRelation() {
+
+}
+
+int main(int argc, char** args) {
+    if (argc != 2) {
+        usage();
+        return 1;
+    }
+    
+    char* input_filename = args[1];
+    
+    if (!openSOSI(input_filename)) {
+        closeSOSI();
+        return 1;
+    }
+    
+    printf("<?xml version=\"1.0\"?>\n"
+        "<osm version=\"0.6\" upload=\"false\" generator=\"sosi2osm\">\n");
+    
+    while (nextSOSIObject()) {
+        short type = getSOSIType();
+        switch(type) {
+        case L_HODE:
+            handleHead();
+            break;
+        case L_FLATE:
+            outputRelation();
+        case L_PUNKT:
+        case L_SYMBOL:
+        case L_TEKST:
+            outputNode();
+            break;
+        case L_KURVE:
+        case L_LINJE:
+        case L_BUEP:
+            outputWay();
+            break;
+        }
+    }
+    
+    printf("</osm>\n");
+    
+    closeSOSI();
+    
+    return 0;
+}
diff --git a/sosi2osm.h b/sosi2osm.h
new file mode 100644
index 0000000..c9ec8cd
--- /dev/null
+++ b/sosi2osm.h
@@ -0,0 +1,13 @@
+#include <fyba.h>
+
+// SOSI
+
+int openSOSI(const char* input_filename);
+void closeSOSI();
+int nextSOSIObject();
+short getSOSIType();
+long getSOSIId();
+const char* getCoordinateSystem();
+void getSOSICoord(int i, double* x, double* y);
+long getSOSICoordsSize();
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/sosi2osm.git



More information about the Pkg-grass-devel mailing list