Changeset: aa9a89b72ede for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=aa9a89b72ede
Added Files:
sql/backends/monet5/vaults/geotiff/73_geotiff.mal
sql/backends/monet5/vaults/geotiff/Makefile.ag
sql/backends/monet5/vaults/geotiff/geotiff.c
sql/backends/monet5/vaults/geotiff/geotiff.h
sql/backends/monet5/vaults/geotiff/geotiff.mal
Modified Files:
MonetDB.spec
configure.ag
sql/backends/monet5/vaults/Makefile.ag
sql/scripts/Makefile.ag
Branch: sciql
Log Message:
imported patch geotiff
diffs (truncated from 557 to 300 lines):
diff --git a/MonetDB.spec b/MonetDB.spec
--- a/MonetDB.spec
+++ b/MonetDB.spec
@@ -584,6 +584,7 @@ developer, but if you do want to test, t
--with-hwcounters=no \
--with-java=no \
--with-mseed=no \
+ --with-geotiff=no \
--with-perl=yes \
--with-pthread=yes \
--with-python=yes \
diff --git a/configure.ag b/configure.ag
--- a/configure.ag
+++ b/configure.ag
@@ -2267,6 +2267,50 @@ AC_SUBST(MSEED_CFLAGS, $MSEED_CFLAGS)
AC_SUBST(MSEED_LIBS, $MSEED_LIBS)
AM_CONDITIONAL(HAVE_MSEED, test x"$have_mseed" != xno)
+
+# geotiff
+have_geotiff="auto"
+AC_ARG_WITH(geotiff,
+ AS_HELP_STRING([--with-geotiff=DIR],[geotiff library is installed in DIR]),
+ [have_geotiff="$withval"], [have_geotiff="auto"])
+if test "x$have_geotiff" != xno; then
+
+ case "$have_geotiff" in
+ auto|yes)
+ ;;
+ *)
+ GEOTIFF_CFLAGS="-I$have_geotiff/include"
+ GEOTIFF_LDFLAGS="-L$have_geotiff/lib"
+ ;;
+ esac
+
+ save_CPPFLAGS="$CPPFLAGS"
+ save_LDFLAGS="$LDFLAGS"
+ save_LIBS="$LIBS"
+ CPPFLAGS="$CPPFLAGS $GEOTIFF_CFLAGS"
+ LDFLAGS="$LDFLAGS $GEOTIFF_LDFLAGS"
+ LIBS=""
+ AC_CHECK_HEADER(tiffio.h, AC_CHECK_LIB(tiff, TIFFOpen))
+ AC_CHECK_HEADER(xtiffio.h,
+ AC_CHECK_LIB(geotiff, XTIFFOpen,
+ [AC_DEFINE(HAVE_GEOTIFF, 1, [Define if you have the
geotiff library])
+ have_geotiff=yes
+ LIBS="$LIBS -lgeotiff"],
+ [ if test "x$have_geotiff" != xauto; then
AC_MSG_ERROR([-lgeotiff library not found]); fi; have_geotiff=no ],
[$MATH_LIBS]),
+ [ if test "x$have_geotiff" != xauto; then
AC_MSG_ERROR([xtiffio.h header not found]); fi; have_geotiff=no ])
+ GEOTIFF_LDFLAGS="$GEOTIFF_LDFLAGS $LIBS"
+ LDFLAGS="$save_LDFLAGS"
+ CPPFLAGS="$save_CPPFLAGS"
+ LIBS="$save_LIBS"
+ if test "x$have_geotiff" != "xyes"; then
+ GEOTIFF_CFLAGS=
+ GEOTIFF_LIBS=""
+ fi
+fi
+AC_SUBST(GEOTIFF_CFLAGS, $GEOTIFF_CFLAGS)
+AC_SUBST(GEOTIFF_LIBS, $GEOTIFF_LDFLAGS)
+AM_CONDITIONAL(HAVE_GEOTIFF, test x"$have_geotiff" != xno)
+
# geos, only used in geom module
have_geos=auto
GEOS_INCS=''
diff --git a/sql/backends/monet5/vaults/Makefile.ag
b/sql/backends/monet5/vaults/Makefile.ag
--- a/sql/backends/monet5/vaults/Makefile.ag
+++ b/sql/backends/monet5/vaults/Makefile.ag
@@ -15,6 +15,8 @@
# Copyright August 2008-2012 MonetDB B.V.
# All Rights Reserved.
+SUBDIRS = HAVE_GEOTIFF?geotiff
+
INCLUDES = ../../../include \
../../../common \
../../../storage \
diff --git a/sql/backends/monet5/vaults/geotiff/73_geotiff.mal
b/sql/backends/monet5/vaults/geotiff/73_geotiff.mal
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/vaults/geotiff/73_geotiff.mal
@@ -0,0 +1,20 @@
+# The contents of this file are subject to the MonetDB Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.monetdb.org/Legal/MonetDBLicense
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+# License for the specific language governing rights and limitations
+# under the License.
+#
+# The Original Code is the MonetDB Database System.
+#
+# The Initial Developer of the Original Code is CWI.
+# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+# Copyright August 2008-2012 MonetDB B.V.
+# All Rights Reserved.
+
+# This loads the MonetDB/SQL module
+library geotiff;
+include geotiff;
diff --git a/sql/backends/monet5/vaults/geotiff/Makefile.ag
b/sql/backends/monet5/vaults/geotiff/Makefile.ag
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/vaults/geotiff/Makefile.ag
@@ -0,0 +1,55 @@
+# The contents of this file are subject to the MonetDB Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.monetdb.org/Legal/MonetDBLicense
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+# License for the specific language governing rights and limitations
+# under the License.
+#
+# The Original Code is the MonetDB Database System.
+#
+# The Initial Developer of the Original Code is CWI.
+# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+# Copyright August 2008-2012 MonetDB B.V.
+# All Rights Reserved.
+
+INCLUDES = ../.. \
+ ../../../../server \
+ ../../../../include \
+ ../../../../common \
+ ../../../../storage \
+ ../../../../../monetdb5/mal \
+ ../../../../../monetdb5/modules/atoms \
+ ../../../../../monetdb5/modules/kernel \
+ ../../../../../monetdb5/modules/mal \
+ ../../../../../monetdb5/optimizer \
+ ../../../../../clients/mapilib \
+ ../../../../../gdk \
+ ../../../../../ \
+ ../../../../../common/stream \
+ ../../../../../common/options \
+ $(GEOTIFF_CFLAGS)
+
+lib__geotiff = {
+ MODULE
+ DIR = libdir/monetdb5
+ SOURCES = geotiff.c geotiff.h
+
+ LIBS = ../../../../../monetdb5/tools/libmonetdb5 $(GEOTIFF_LIBS)
+}
+
+headers_geotiff_mal = {
+ HEADERS = mal
+ DIR = libdir/monetdb5
+ SOURCES = geotiff.mal
+}
+
+headers_autoload = {
+ HEADERS = mal
+ DIR = libdir/monetdb5/autoload
+ SOURCES = 73_geotiff.mal
+}
+
+EXTRA_DIST = geotiff.h geotiff.mal 73_geotiff.mal
diff --git a/sql/backends/monet5/vaults/geotiff/geotiff.c
b/sql/backends/monet5/vaults/geotiff/geotiff.c
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/vaults/geotiff/geotiff.c
@@ -0,0 +1,292 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2012 MonetDB B.V.
+ * All Rights Reserved.
+*/
+
+#include <monetdb_config.h>
+#include "geotiff.h"
+#include "sql_mvc.h"
+#include "sql.h"
+#include "sql_scenario.h"
+#include "mal_exception.h"
+#include <xtiffio.h> /* for TIFF */
+
+
+#define INSFILE "INSERT INTO rs.files(fileid,location,status,lastmodified) \
+ VALUES(%d, '%s', %d, CURRENT_TIMESTAMP());"
+#define INSCAT "INSERT INTO rs.catalog(imageid,fileid,width,length,bps) \
+ VALUES(%d, %d, %d, %d, %d);"
+#define CRTIMAGE "CREATE ARRAY %s (x int dimension[%d], \
+ y int dimension[%d], v %s);"
+
+/* CURRENT_TIMESTAMP() ?*/
+
+str
+GTIFFtest(int *wid, int *len, str *fname)
+{
+ TIFF *tif = (TIFF*)0; /* TIFF-level descriptor */
+ str msg = MAL_SUCCEED;
+
+ /* Open TIFF descriptor */
+ tif = XTIFFOpen(*fname, "r");
+ if (!tif)
+ return createException(MAL, "gtiff.test", "Missing GEOTIFF file
%s", *fname);
+ TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, wid);
+ TIFFGetField(tif,TIFFTAG_IMAGELENGTH, len);
+ XTIFFClose(tif);
+
+ return msg;
+}
+
+/* attach a single geotiff file given its name, fill in geotiff catalog tables
*/
+
+str
+GTIFFattach(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ mvc *m = NULL;
+ sql_schema *sch = NULL;
+ sql_table *fls = NULL, *cat = NULL;
+ sql_column *col;
+ str msg = MAL_SUCCEED;
+ str fname = *(str*)getArgReference(stk, pci, 1);
+ TIFF *tif = (TIFF*)0; /* TIFF-level descriptor */
+ char buf[BUFSIZ], *s= buf;
+ int wid = 0, len = 0;
+ oid fid, imid, rid = oid_nil;
+ sht bps;
+
+ msg = getSQLContext(cntxt, mb, &m, NULL);
+ if (msg)
+ return msg;
+
+ sch = mvc_bind_schema(m, "rs");
+ if ( !sch )
+ return createException(MAL, "geotiff.attach", "Schema rs
missing\n");
+
+ fls = mvc_bind_table(m, sch, "files");
+ cat = mvc_bind_table(m, sch, "catalog");
+ if (fls == NULL || cat == NULL )
+ return createException(MAL, "geotiff.attach", "Catalog table
missing\n");
+
+ tif = XTIFFOpen(fname, "r");
+ if (!tif)
+ return createException(MAL, "geotiff.attach", "Missing GEOTIFF
file %s\n", fname);
+
+ /* check if the file is already attached */
+ col = mvc_bind_column(m, fls, "location");
+ rid = table_funcs.column_find_row(m->session->tr, col, fname, NULL);
+ if (rid != oid_nil) {
+ XTIFFClose(tif);
+ msg = createException(SQL, "geotiff.attach", "File %s already
attached\n", fname);
+ return msg; /* just return success ?*/
+ }
+
+ /* add row in the rs.files catalog table */
+ col = mvc_bind_column(m, fls, "fileid");
+ fid = store_funcs.count_col(col) + 1;
+
+ snprintf(buf, BUFSIZ, INSFILE, (int)fid, fname, 0);
+ if ( ( msg = SQLstatementIntern(cntxt,&s,"geotiff.attach",TRUE,FALSE))
!= MAL_SUCCEED)
+ goto finish;
+
+
+ /* add row in the rs.catalog catalog table */
+ col = mvc_bind_column(m, cat, "imageid");
+ imid = store_funcs.count_col(col) + 1;
+ TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &wid);
+ TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &len);
+ TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bps);
+
+ snprintf(buf, BUFSIZ, INSCAT, (int)imid, (int)fid, wid, len, bps);
+ msg = SQLstatementIntern(cntxt,&s,"geotiff.attach",TRUE,FALSE);
+
+ finish:
+ /* if (msg != MAL_SUCCEED){
+ snprintf(buf, BUFSIZ,"ROLLBACK;");
+ SQLstatementIntern(cntxt,&s,"geotiff.attach",TRUE,FALSE));
+ }*/
+ XTIFFClose(tif);
+ return msg;
+}
+
+str
+GTIFFloadImage(bat *result, str *fname)
+{
+ TIFF *tif = (TIFF*)0;
+ int wid = 0, len = 0;
+ BUN pixels = BUN_NONE, strsize = BUN_NONE, sz = BUN_NONE;
+ sht photoint, bps;
+ tsize_t strcnt, i;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list