Nov 14 2010

UCOSP — Integrating KML into SQL Stub function">UCOSP — Integrating KML into SQL Stub function

So, this week I embarked on the jour­ney to get my asKML func­tion work­ing end-to-end. At this moment, I’ve imple­mented the well known binary to kml con­ver­sion, and I’ve also made a stub SQL file asKML which sim­ply returns the same as asBi­nary, but I wanted to get them work­ing together. I ran into a lit­tle road­block and I’ve been wait­ing on one of the Ingres devel­op­ers to give me a hand, as I am a lit­tle stuck.

So, I tried doing a few things, but I haven’t been able to get a build going with my changes. Here is what I did:

Firstly, I made the asKML func­tion return geom_to_kml, instead of just geom_to_text, repli­cat­ing the asText func­tion. And in the call to geom_to_kml, I copied the func­tion­al­ity of asBi­nary, as you (Chuck) stated that there is stuff that I will need from asBi­nary if I am going from WKB to KML (which I am!). This was all fine, I built the project, and when exe­cut­ing asKML in the SQL state­ments, it returned WKB.

After­wards, I added some of my code to try and con­vert WKB into KML. I didn’t write any of the code for return­ing the value, I just added TRdis­play func­tions to print the results. The thing is, I’m still not sure where to actu­ally grab the wkb… Based on the code I took a guess, but I could be wrong. This is what I added inside the geom_to_kml function:


/* Con­vert wkb into kml */
OGR­Err eErr;
OGR­Ge­om­e­tryH hGeom = NULL;
char *kml = NULL;
unsigned char *wkb_buffer = &dv_wkb.db_data;
if( eErr == OGRERR_NONE )
{
kml = OGR_G_ExportToKML( hGeom, “???I do not know what this is” );
OGR_G_DestroyGeometry( hGeom );
TRdis­play( “kml = %s\n”, kml );
//CPLFree( kml );
}
else if( eErr == OGRERR_NOT_ENOUGH_DATA )
{
TRdis­play( “error2”);
}
else if( eErr == OGRERR_UNSUPPORTED_GEOMETRY_TYPE )
{
TRdis­play( “error2” );
}
else if( eErr == OGRERR_CORRUPT_DATA )
{
TRdis­play( “error3” );
};

After adding this, I did a build, and ran into a build error. Here it is:


Extract­ing objects …
ld –shared –melf_x86_64 –z noex­ec­stack –L/lib64 –L/usr/lib64 –o /home/sjansepar/Ingres/build/lib/libframe.1.so *.o –lrt –lm –lc –lpthread –ldl –lcrypt
–rwxr-xr-x. 1 sjansepar sjansepar 1514314 Nov 11 18:56 /home/sjansepar/Ingres/build/lib/libframe.1.so
Clean­ing up .…
Link /home/sjansepar/Ingres/build/sig/rpclean/rpclean
/home/sjansepar/Ingres/build/lib/libq.1.so: unde­fined ref­er­ence to ‘OGR_G_DestroyGeometry’
/home/sjansepar/Ingres/build/lib/libq.1.so: unde­fined ref­er­ence to ‘OGR_G_ExportToKML’
collect2: ld returned 1 exit sta­tus

I did include the library:


#include <ogr_api.h>

I may be miss­ing a step through, maybe there is some­thing I need to do for the build to use the libgdal…

I am also not sure If the fol­low­ing line is cor­rect for access­ing the binary data:


unsigned char *wkb_buffer = &dv_wkb.db_data;

wbk_buffer is sup­pose to be a pointer to a char, and I’m not sure that I am right here as to where I’m get­ting the binary data.

Thats where I’m at right now! Hope­fully I’ll get some help soon and I will make a bit more progress.

Shawn


Nov 14 2010

UCOSP — Ingres SQL Function Implementation">UCOSP — Ingres SQL Function Implementation

Hey all!

So, its been a bit of a strug­gle but with the highly appre­ci­ated help from Chuck ‚I have been able to get the asKML func­tion up and run­ning! I fol­lowed the fol­low­ing doc­u­ment to get this going:

http://community.ingres.com/wiki/Implementing_New_SQL_Function

It was a bit dif­fi­cult to fol­low, but I got it even­tu­ally. Its nec­es­sary to fol­low this doc­u­ment VERY pre­cisely in order to get it work­ing. Here is a diff that was nec­es­sary to get it working:

diff –git a/src/common/adf/adg/fi_defn.txt b/src/common/adf/adg/fi_defn.txt
index 668c9f1..ed86a3d 100644
— a/src/common/adf/adg/fi_defn.txt
+++ b/src/common/adf/adg/fi_defn.txt
@@ –10347,6 +10347,17 @@ group ADI_NORM_FUNC
operands DB_LBYTE_TYPE DB_INT_TYPE
rou­tine adu_geometrycollection_srid_fromWKB

+    oper­a­tor ADI_GEOMKML_OP type ADI_PREFIX
+        name “asKML” sup­port ADI_INGRES_6
+
+    fi ADFI_1701_GEOM_AS_KML
+        descrip­tion geom    : asKML(geom)
+        lenspec ADI_FIXED sizeof(ADP_PERIPHERAL)
+        null_preinst ADE_1CXI_SET_SKIP
+        result DB_LVCH_TYPE
+        operands DB_GEOM_TYPE
+        rou­tine adu_geom_asKML
+


group ADI_COPY_COERCION
diff –git a/src/common/adf/adu/aduspatial.c b/src/common/adf/adu/aduspatial.c
index 2d45993..83f9d30 100644
— a/src/common/adf/adu/aduspatial.c
+++ b/src/common/adf/adu/aduspatial.c
@@ –2514,6 +2514,25 @@ DB_DATA_VALUE   *dv_out)
#endif
}

+/*
+ * This func­tion takes the stored data, splits out the geom­e­try from the stream
+ * and con­verts it to KML.
+ */
+DB_STATUS
+adu_geom_asKML(
+ADF_CB          *adf_scb,
+DB_DATA_VALUE   *dv_in,
+DB_DATA_VALUE   *dv_out)
+{
+#ifn­def _WITH_GEO
+    return (adu_error(adf_scb, E_AD5606_SPATIAL_NOT_SUPPORTED, 2, 0));
+#else
+    TRdisplay(“AsKML\n”);
+    return geom_to_text(adf_scb, dv_in, dv_out, TRUE, FULL_PRECISION);
+    //return “Hello KML”;
+#endif
+}
+
DB_STATUS
adu_geom_asTextRaw(
ADF_CB          *adf_scb,
diff –git a/src/common/adf/hdr/adffiids.h b/src/common/adf/hdr/adffiids.h
index 91e72b9..f690e4c 100644
— a/src/common/adf/hdr/adffiids.h
+++ b/src/common/adf/hdr/adffiids.h
@@ –1884,3 +1884,4 @@
#define ADFI_1698_GEOMC_FROM_WKB        (ADI_FI_ID)1698 /* geomcollfromwkb(bin) */
#define ADFI_1699_GEOMC_S_FROM_TEXT     (ADI_FI_ID)1699 /* geomcollfromtext(text, int) */
#define ADFI_1700_GEOMC_S_FROM_WKB      (ADI_FI_ID)1700 /* geomcollfromwkb(bin,int) */
+#define ADFI_1701_GEOM_AS_KML           (ADI_FI_ID)1701 /* asKML(lbyte) */
diff –git a/src/common/adf/hdr/aduint.h b/src/common/adf/hdr/aduint.h
index 635cd3c..c54ee63 100644
— a/src/common/adf/hdr/aduint.h
+++ b/src/common/adf/hdr/aduint.h
@@ –765,6 +765,8 @@ FUNC_EXTERN ADU_NORM2_FUNC adu_geom_asTextRound; /* Con­vert a geom­e­try to WKT
with spec­i­fied round­ing */
FUNC_EXTERN ADU_NORM1_FUNC adu_geom_asBinary; /* Con­vert a geom­e­try to WKB. */

+FUNC_EXTERN ADU_NORM1_FUNC adu_geom_asKML; /* Con­vert a geom­e­try to KML. */
+
FUNC_EXTERN ADU_NORM2_FUNC adu_geom_nbr; /* Extract an nbr for rtree index­ing */
FUNC_EXTERN ADU_NORM1_FUNC adu_geom_hilbert; /* Find the hilbert num­ber for rtree index­ing */
FUNC_EXTERN ADU_NORM1_FUNC adu_geom_perimeter; /* Get the perime­ter of a spa­tial objext. */
diff –git a/src/common/hdr/hdr/adfops.h b/src/common/hdr/hdr/adfops.h
index d0a111e..fe06b1b 100644
— a/src/common/hdr/hdr/adfops.h
+++ b/src/common/hdr/hdr/adfops.h
@@ –503,6 +503,7 @@ _DEFINE(NUMPOINTS,   299  /* NUMPOINTS(linestring)   */)\
_DEFINE(TRANSFORM,   300  /* TRANSFORM(geom)         */)\
_DEFINE(GEOMWKTRAW,    301  /* AsTextRaw(geom)         */)\
_DEFINE(GEOMC,   302 /* Geom­Coll oper­a­tors   */)\
+_DEFINE(GEOMKML,         303  /* asKML(geom) */)\
_DEFINEEND



I did run into a bit of trou­ble, cou­ple errors in the process, but a big thing to get it work­ing was run­ning the buildtools/cleanup.sh com­mand. It blows away every arti­fact that I could have, and leaves no legacy stuff that could have been inter­fear­ing with the process. Before I tried build­ing after chang­ing the code with­out run­ning the cleanup script, I would get an error inform­ing me that there is no “askml” func­tion. After the cleanup.sh script, all went well!
At the moment, so far I have the abil­ity to type asKML with a cer­tain datatype, but it is not doing any­thing spe­cial — it is sim­ply doing the same func­tion­al­ity as asText. The next step is to take my code that con­verts WKB to KML, and inte­grate it into the aduspatial.c file.

Till next week!

Shawn