LCOV - code coverage report
Current view: top level - sql/backends/monet5/vaults/shp - shp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 289 0.7 %
Date: 2021-10-13 02:24:04 Functions: 1 10 10.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /*
      10             :  * Authors: K. Kyzirakos, D. Savva
      11             :  * This module contains primitives for accessing geospatial data
      12             :  * stored in ESRI Shapefile documents.
      13             :  */
      14             : 
      15             : #include "monetdb_config.h"
      16             : #include <string.h>
      17             : #include "sql_mvc.h"
      18             : #include "sql.h"
      19             : #ifndef __clang_major__         /* stupid include file gdal/cpl_port.h */
      20             : #define __clang_major__ 0
      21             : #endif
      22             : #include "shp.h"
      23             : #include <cpl_conv.h>             /* for CPLFree */
      24             : #include "sql_execute.h"
      25             : #include "mal_exception.h"
      26             : 
      27             : #include "libgeom.h"
      28             : 
      29             : /* FIXME: the use of the 'rs' schema should be reconsidered so that the geotiff
      30             :  * catalog can be integrated into the SQL catalog.
      31             :  * When removing the 'rs' schame, the code of client/mapiclient/dump.c MUST be
      32             :  * adapted accordingly.
      33             :  */
      34             : 
      35             : /*#define BUFSIZ 524288*/
      36             : 
      37             : /*void getMBB(char * source) {
      38             :         SBNSearchHandle handle;
      39             :         char * name;
      40             :         int i;
      41             : 
      42             :         name = malloc((strlen(source) + 1) * sizeof(char));
      43             :         for (i=0 ; i<strlen(source) + 1 ; i++) {
      44             :                 if (i == strlen(source)) {
      45             :                         name[i] = '\0';
      46             :                 }
      47             :                 else if (i == strlen(source) - 1) {
      48             :                         name[i] = 'n';
      49             :                 }
      50             :                 else if (i == strlen(source) - 2) {
      51             :                         name[i] = 'b';
      52             :                 }
      53             :                 else if (i == strlen(source) - 3) {
      54             :                         name[i] = 's';
      55             :                 }
      56             :                 else {
      57             :                         name[i] = source[i];
      58             :                 }
      59             :         }
      60             :         handle = SBNOpenDiskTree(source, NULL);
      61             : }*/
      62             : 
      63           0 : GDALWConnection * GDALWConnect(char * source) {
      64             :         GDALWConnection * conn = NULL;
      65             :         OGRFeatureDefnH featureDefn;
      66             :         int fieldCount, i;
      67           0 :         OGRRegisterAll();
      68           0 :         conn = malloc(sizeof(GDALWConnection));
      69           0 :         if (conn == NULL) {
      70           0 :                 TRC_ERROR(SHP, "Could not allocate memory\n");
      71           0 :                 return NULL;
      72             :         }
      73           0 :         conn->handler = OGROpen(source, 0 , &(conn->driver));
      74           0 :         if (conn->handler == NULL) {
      75           0 :                 free(conn);
      76           0 :                 return NULL;
      77             :         }
      78             : 
      79             : 
      80           0 :         conn->layer = OGR_DS_GetLayer(conn->handler, 0);
      81           0 :         if (conn->layer == NULL) {
      82           0 :                 OGRReleaseDataSource(conn->handler);
      83           0 :                 free(conn);
      84           0 :                 return NULL;
      85             :         }
      86             : 
      87           0 :         conn->layername = (const char *) OGR_L_GetName(conn->layer);
      88             : 
      89           0 :         featureDefn = OGR_L_GetLayerDefn(conn->layer);
      90           0 :         fieldCount = OGR_FD_GetFieldCount(featureDefn);
      91           0 :         conn->numFieldDefinitions = fieldCount;
      92           0 :         conn->fieldDefinitions = malloc(fieldCount * sizeof(OGRFieldDefnH));
      93           0 :         if (conn->fieldDefinitions == NULL) {
      94           0 :                 OGRReleaseDataSource(conn->handler);
      95           0 :                 free(conn);
      96           0 :                 TRC_ERROR(SHP, "Could not allocate memory\n");
      97           0 :                 return NULL;
      98             :         }
      99           0 :         for (i=0 ; i<fieldCount ; i++) {
     100           0 :                 conn->fieldDefinitions[i] = OGR_FD_GetFieldDefn(featureDefn, i);
     101             :         }
     102             : 
     103             :         return conn;
     104             : }
     105             : 
     106           0 : void GDALWClose(GDALWConnection * conn) {
     107           0 :         free(conn->fieldDefinitions);
     108           0 :         OGRReleaseDataSource(conn->handler);
     109           0 : }
     110             : 
     111           0 : GDALWSimpleFieldDef * GDALWGetSimpleFieldDefinitions(GDALWConnection conn) {
     112             :         int i;
     113             :         GDALWSimpleFieldDef * columns;
     114             :         OGRFieldDefnH fieldDefn;
     115             :         /*if (conn.layer == NULL || conn.handler == NULL || conn.driver == NULL) {
     116             :                 printf("Could not extract columns, initialize a connection first.\n");
     117             :                 exit(-1);
     118             :         }*/
     119           0 :         columns = malloc(conn.numFieldDefinitions * sizeof(GDALWSimpleFieldDef));
     120           0 :         if (columns == NULL) {
     121           0 :                 TRC_ERROR(SHP, "Could not allocate memory\n");
     122           0 :                 return NULL;
     123             :         }
     124           0 :         for (i=0 ; i<conn.numFieldDefinitions ; i++) {
     125           0 :                 fieldDefn = conn.fieldDefinitions[i];
     126           0 :                 columns[i].fieldName = OGR_Fld_GetNameRef(fieldDefn);
     127           0 :                 columns[i].fieldType = OGR_GetFieldTypeName(OGR_Fld_GetType(fieldDefn));
     128             :         }
     129             : 
     130             :         return columns;
     131             : }
     132             : 
     133           0 : void GDALWPrintRecords(GDALWConnection conn) {
     134             :         char * wkt;
     135             :         int i;
     136             :         OGRFeatureH feature;
     137             :         OGRGeometryH geometry;
     138             :         OGRFeatureDefnH featureDefn;
     139           0 :         featureDefn = OGR_L_GetLayerDefn(conn.layer);
     140           0 :         OGR_L_ResetReading(conn.layer);
     141           0 :         while( (feature = OGR_L_GetNextFeature(conn.layer)) != NULL ) {
     142           0 :                 for(i = 0; i < OGR_FD_GetFieldCount(featureDefn); i++ ) {
     143           0 :                         OGRFieldDefnH hFieldDefn = OGR_FD_GetFieldDefn( featureDefn, i );
     144           0 :                     if( OGR_Fld_GetType(hFieldDefn) == OFTInteger )
     145           0 :                         printf( "%d,", OGR_F_GetFieldAsInteger( feature, i ) );
     146           0 :                     else if( OGR_Fld_GetType(hFieldDefn) == OFTReal )
     147           0 :                         printf( "%.3f,", OGR_F_GetFieldAsDouble( feature, i) );
     148             :                     else
     149           0 :                         printf( "%s,", OGR_F_GetFieldAsString( feature, i) );
     150             : 
     151             :                 }
     152           0 :                 geometry = OGR_F_GetGeometryRef(feature);
     153           0 :                 OGR_G_ExportToWkt(geometry, &wkt);
     154           0 :                 printf("%s", wkt);
     155           0 :                 printf("\n");
     156           0 :                 CPLFree(wkt);
     157           0 :                 OGR_F_Destroy(feature);
     158             :         }
     159           0 : }
     160             : 
     161           0 : GDALWSpatialInfo GDALWGetSpatialInfo(GDALWConnection conn) {
     162             :         GDALWSpatialInfo spatialInfo;
     163           0 :         OGRSpatialReferenceH spatialRef = OGR_L_GetSpatialRef(conn.layer);
     164             :         char * proj4, * srsText, * srid;
     165             : 
     166           0 :         OSRExportToProj4(spatialRef, &proj4);
     167           0 :         OSRExportToWkt(spatialRef, &srsText);
     168           0 :         srid = (char *) OSRGetAttrValue(spatialRef, "AUTHORITY", 1);
     169           0 :         if (srid == NULL) {
     170             :                 spatialInfo.epsg = 4326;
     171             :         }
     172             :         else {
     173           0 :                 spatialInfo.epsg = atoi(OSRGetAttrValue(spatialRef, "AUTHORITY", 1));
     174             :         }
     175           0 :         spatialInfo.authName = OSRGetAttrValue(spatialRef, "AUTHORITY", 0);
     176           0 :         if (spatialInfo.authName == NULL) {
     177             :                 spatialInfo.authName = "EPSG";
     178             :         }
     179           0 :         spatialInfo.proj4Text = proj4;
     180           0 :         spatialInfo.srsText = srsText;
     181             : 
     182           0 :         return spatialInfo;
     183             : 
     184             : }
     185             : 
     186             : /* attach a single shp file given its name, fill in shp catalog tables */
     187             : str
     188           0 : SHPattach(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
     189             : {
     190           0 :         mvc *m = NULL;
     191             :         sql_schema *sch = NULL;
     192             :         sql_table *fls = NULL, *shps = NULL, *shps_dbf = NULL;
     193             :         sql_column *col;
     194             :         str msg = MAL_SUCCEED;
     195           0 :         str fname = *(str*)getArgReference(stk, pci, 1);
     196             :         /* SHP-level descriptor */
     197             :         char buf[BUFSIZ], temp_buf[BUFSIZ], *s=buf;
     198             :         int  i=0, shpid = 0;
     199             :         oid fid, rid = oid_nil;
     200             :         GDALWConnection shp_conn;
     201             :         GDALWConnection * shp_conn_ptr = NULL;
     202             :         GDALWSimpleFieldDef * field_definitions;
     203             :         GDALWSpatialInfo spatial_info;
     204             : 
     205             :         char *nameToLowerCase = NULL;
     206             : 
     207           0 :         if((msg = getSQLContext(cntxt, mb, &m, NULL)) != MAL_SUCCEED)
     208             :                 return msg;
     209           0 :         if((msg = checkSQLContext(cntxt)) != MAL_SUCCEED)
     210             :                 return msg;
     211             : 
     212           0 :         if(!(sch = mvc_bind_schema(m, "sys")))
     213           0 :                 return createException(MAL, "shp.attach", SQLSTATE(38000) "Schema sys missing\n");
     214             : 
     215           0 :         fls = mvc_bind_table(m, sch, "files");
     216           0 :         shps = mvc_bind_table(m, sch, "shapefiles");
     217           0 :         shps_dbf = mvc_bind_table(m, sch, "shapefiles_dbf");
     218           0 :         if (fls == NULL || shps == NULL || shps_dbf == NULL )
     219           0 :                 return createException(MAL, "shp.attach", SQLSTATE(38000) "Catalog table missing\n");
     220             : 
     221           0 :         if ((shp_conn_ptr = GDALWConnect((char *) fname)) == NULL) {
     222           0 :                 return createException(MAL, "shp.attach", SQLSTATE(38000) "Missing shape file %s\n", fname);
     223             :         }
     224           0 :         shp_conn = *shp_conn_ptr;
     225             : 
     226             :         /* check if the file is already attached */
     227           0 :         col = mvc_bind_column(m, fls, "path");
     228           0 :         sqlstore *store = m->session->tr->store;
     229           0 :         rid = store->table_api.column_find_row(m->session->tr, col, fname, NULL);
     230           0 :         if (!is_oid_nil(rid)) {
     231           0 :                 GDALWClose(shp_conn_ptr);
     232           0 :                 return createException(MAL, "shp.attach", SQLSTATE(38000) "File %s already attached\n", fname);
     233             :         }
     234             : 
     235             :         /* add row in the files(id, path) catalog table */
     236           0 :         col = mvc_bind_column(m, fls, "id");
     237           0 :         fid = store->storage_api.count_col(m->session->tr, col, 1) + 1;
     238           0 :         snprintf(buf, BUFSIZ, INSFILE, (int)fid, fname);
     239           0 :         if ( ( msg = SQLstatementIntern(cntxt, s,"shp.attach",TRUE,FALSE,NULL)) != MAL_SUCCEED)
     240           0 :                 goto finish;
     241             : 
     242             : 
     243             :         /*if (shp_conn.layer == NULL || shp_conn.source == NULL || shp_conn.handler == NULL || shp_conn.driver == NULL) {
     244             :                 msg = createException(MAL, "shp.attach", SQLSTATE(38000) "lol-1\n");
     245             :                                                                         return msg;
     246             :         }*/
     247             : 
     248             :         /* add row in the shapefiles catalog table (e.g. the name of the table that will store tha data of the shapefile) */
     249           0 :         spatial_info = GDALWGetSpatialInfo(shp_conn);
     250           0 :         col = mvc_bind_column(m, shps, "shapefileid");
     251           0 :         shpid = store->storage_api.count_col(m->session->tr, col, 1) + 1;
     252           0 :         nameToLowerCase = toLower(shp_conn.layername);
     253           0 :         snprintf(buf, BUFSIZ, INSSHP, shpid, (int)fid, spatial_info.epsg, nameToLowerCase);
     254           0 :         GDKfree(nameToLowerCase);
     255           0 :         if ( ( msg = SQLstatementIntern(cntxt, s,"shp.attach",TRUE,FALSE,NULL)) != MAL_SUCCEED)
     256           0 :                         goto finish;
     257             : 
     258             :         /* add information about the fields of the shape file
     259             :         * one row for each field with info (shapefile_id, field_name, field_type) */
     260           0 :         field_definitions = GDALWGetSimpleFieldDefinitions(shp_conn);
     261           0 :         if (field_definitions == NULL) {
     262           0 :                 GDALWClose(&shp_conn);
     263           0 :                 return createException(MAL, "shp.attach", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     264             :         }
     265           0 :         for (i=0 ; i<shp_conn.numFieldDefinitions ; i++) {
     266           0 :                 snprintf(buf, BUFSIZ, INSSHPDBF, shpid, field_definitions[i].fieldName, field_definitions[i].fieldType);
     267           0 :                 if ( ( msg = SQLstatementIntern(cntxt, s,"shp.attach",TRUE,FALSE,NULL)) != MAL_SUCCEED)
     268           0 :                         goto fin;
     269             :         }
     270             : 
     271             :         /* create the table that will store the data of the shape file */
     272           0 :         temp_buf[0]='\0';
     273           0 :         for (i=0 ; i<shp_conn.numFieldDefinitions ; i++) {
     274           0 :                 nameToLowerCase = toLower(field_definitions[i].fieldName);
     275           0 :                 if (strcmp(field_definitions[i].fieldType, "Integer") == 0) {
     276           0 :                         sprintf(temp_buf + strlen(temp_buf), "\"%s\" INT, ", nameToLowerCase);
     277           0 :                 } else if (strcmp(field_definitions[i].fieldType, "Real") == 0) {
     278           0 :                         sprintf(temp_buf + strlen(temp_buf), "\"%s\" FLOAT, ", nameToLowerCase);
     279             : #if 0
     280             :                 } else if (strcmp(field_definitions[i].fieldType, "Date") == 0) {
     281             :                         sprintf(temp_buf + strlen(temp_buf), "\"%s\" STRING, ", nameToLowerCase);
     282             : #endif
     283             :                 } else
     284           0 :                         sprintf(temp_buf + strlen(temp_buf), "\"%s\" STRING, ", nameToLowerCase);
     285           0 :                 GDKfree(nameToLowerCase);
     286             :         }
     287             : 
     288           0 :         sprintf(temp_buf + strlen(temp_buf), "geom GEOMETRY ");
     289           0 :         snprintf(buf, BUFSIZ, CRTTBL, shp_conn.layername, temp_buf);
     290             : 
     291           0 :         if ( ( msg = SQLstatementIntern(cntxt, s,"shp.import",TRUE,FALSE,NULL)) != MAL_SUCCEED)
     292           0 :                 goto fin;
     293             : 
     294           0 : fin:
     295           0 :         free(field_definitions);
     296           0 : finish:
     297             :         /* if (msg != MAL_SUCCEED){
     298             :            snprintf(buf, BUFSIZ,"ROLLBACK;");
     299             :            SQLstatementIntern(cntxt,s,"geotiff.attach",TRUE,FALSE));
     300             :            }*/
     301           0 :         GDALWClose(&shp_conn);
     302           0 :         return msg;
     303             : }
     304             : 
     305             : 
     306             : 
     307             : static str
     308           0 : SHPimportFile(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, bool partial)
     309             : {
     310           0 :         mvc *m = NULL;
     311             :         sql_schema *sch = NULL;
     312             :         char *sch_name = "sys";
     313             : 
     314             :         sql_table *shps_table = NULL, *fls_table = NULL, *data_table = NULL;
     315             :         char *shps_table_name = "shapefiles";
     316             :         char *fls_table_name = "files";
     317             :         char *data_table_name = NULL;
     318             : 
     319             :         sql_column *col;
     320             : 
     321             :         sql_column **cols;
     322           0 :         BAT **colsBAT, *pos = NULL;
     323             :         BUN offset;
     324             :         int colsNum = 2; //we will have at least the gid column and a geometry column
     325             :         int rowsNum = 0; //the number of rows in the shape file that will be imported
     326             :         //GIntBig rowsNum = 0;
     327             :         int gidNum = 0;
     328             :         char *nameToLowerCase = NULL;
     329             : 
     330             :         str msg = MAL_SUCCEED;
     331             :         str fname = NULL;
     332           0 :         int vid = *(int*)getArgReference(stk, pci, 1);
     333             :         ptr *p;
     334             :         wkb *g;
     335             :         OGRGeometryH geom;
     336             :         OGREnvelope *mbb;
     337             :         /* SHP-level descriptor */
     338             :         OGRFieldDefnH hFieldDefn;
     339             :         int  i=0;
     340             :         oid irid;
     341             :         GDALWConnection shp_conn;
     342             :         GDALWConnection * shp_conn_ptr = NULL;
     343             :         GDALWSimpleFieldDef * field_definitions;
     344             :         OGRFeatureH feature;
     345             :         OGRFeatureDefnH featureDefn;
     346             : 
     347             :         /* get table columns from shp and create the table */
     348             : 
     349           0 :         if((msg = getSQLContext(cntxt, mb, &m, NULL)) != MAL_SUCCEED)
     350             :                 return msg;
     351           0 :         if((msg = checkSQLContext(cntxt)) != MAL_SUCCEED)
     352             :                 return msg;
     353             : 
     354           0 :         if(!(sch = mvc_bind_schema(m, sch_name)))
     355           0 :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Schema '%s' missing", sch_name);
     356             : 
     357             :         /* find the name of the shape file corresponding to the given id */
     358           0 :         if(!(fls_table = mvc_bind_table(m, sch, fls_table_name)))
     359           0 :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Table '%s.%s' missing", sch_name, fls_table_name);
     360           0 :         if(!(col = mvc_bind_column(m, fls_table, "id")))
     361           0 :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(id)' missing", sch_name, fls_table_name);
     362           0 :         sqlstore *store = m->session->tr->store;
     363           0 :         irid = store->table_api.column_find_row(m->session->tr, col, (void *)&vid, NULL);
     364           0 :         if (is_oid_nil(irid))
     365           0 :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Shapefile with id %d not in the %s.%s table\n", vid, sch_name, fls_table_name);
     366           0 :         if(!(col = mvc_bind_column(m, fls_table, "path")))
     367           0 :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(path)' missing", sch_name, fls_table_name);
     368           0 :         fname = (str)store->table_api.column_find_value(m->session->tr, col, irid);
     369             : 
     370             :         /* find the name of the table that has been reserved for this shape file */
     371           0 :         if(!(shps_table = mvc_bind_table(m, sch, shps_table_name)))
     372           0 :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Table '%s.%s' missing", sch_name, shps_table_name);
     373           0 :         if(!(col = mvc_bind_column(m, shps_table, "fileid")))
     374           0 :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(fileid)' missing", sch_name, shps_table_name);
     375           0 :         irid = store->table_api.column_find_row(m->session->tr, col, (void *)&vid, NULL);
     376           0 :         if (is_oid_nil(irid))
     377           0 :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Shapefile with id %d not in the Shapefile catalog\n", vid);
     378           0 :         if(!(col = mvc_bind_column(m, shps_table, "datatable")))
     379           0 :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(datatable)' missing", sch_name, shps_table_name);
     380           0 :         data_table_name = (str)store->table_api.column_find_value(m->session->tr, col, irid);
     381             : 
     382             : 
     383             :         /* add the data on the file to the table */
     384           0 :         if(!(shp_conn_ptr = GDALWConnect((char *) fname)))
     385           0 :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Missing shape file %s\n", fname);
     386           0 :         shp_conn = *shp_conn_ptr;
     387             : 
     388             :         /*count the number of lines in the shape file */
     389           0 :         if ((rowsNum = OGR_L_GetFeatureCount(shp_conn.layer, false)) == -1) {
     390           0 :                 if ((rowsNum = OGR_L_GetFeatureCount(shp_conn.layer, true)) == -1) {
     391           0 :                         OGR_L_ResetReading(shp_conn.layer);
     392             :                         rowsNum = 0;
     393           0 :                         while ((feature = OGR_L_GetNextFeature(shp_conn.layer)) != NULL ) {
     394           0 :                                 rowsNum++;
     395           0 :                                 OGR_F_Destroy(feature);
     396             :                         }
     397             :                 }
     398             :         }
     399             : 
     400             :         /* calculate the mbb of the query geometry */
     401           0 :         if (partial) {
     402           0 :                 p = (ptr*)getArgReference(stk, pci, 2);
     403           0 :                 g = (wkb*)*p;
     404           0 :                 geom = OGR_G_CreateGeometry(wkbPolygon);
     405           0 :                 if (OGR_G_ImportFromWkb(geom, (unsigned char*)g->data, g->len) != OGRERR_NONE) {
     406           0 :                         msg = createException(MAL, "shp.import", SQLSTATE(38000) "Could not intantiate the query polygon.");
     407           0 :                         OGR_F_Destroy(geom);
     408           0 :                         goto final;
     409             :                 }
     410           0 :                 if (!(mbb = (OGREnvelope*)GDKmalloc(sizeof(OGREnvelope)))) {
     411           0 :                         msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     412           0 :                         OGR_F_Destroy(geom);
     413           0 :                         goto final;
     414             :                 }
     415           0 :                 OGR_G_GetEnvelope(geom, mbb);
     416             : 
     417             :                 //FIXME: Take into account the coordinate reference system
     418             : 
     419             :                 /* apply the spatial filter */
     420           0 :                 OGR_L_SetSpatialFilterRect(shp_conn.layer, mbb->MinX, mbb->MinY, mbb->MaxX, mbb->MaxY);
     421             : 
     422           0 :                 OGR_F_Destroy(mbb);
     423           0 :                 OGR_F_Destroy(geom);
     424             :         }
     425             : 
     426             :         /* bind the columns of the data file that was just created
     427             :         * and create a BAT for each of the columns */
     428           0 :         if(!(data_table = mvc_bind_table(m, sch, data_table_name))) {
     429           0 :                 msg = createException(MAL, "shp.import", SQLSTATE(42SO2) "Table '%s.%s' missing", sch_name, data_table_name);
     430           0 :                 goto final;
     431             :         }
     432           0 :         colsNum += shp_conn.numFieldDefinitions;
     433           0 :         if(!(cols = (sql_column**)GDKmalloc(sizeof(sql_column*)*colsNum))) {
     434           0 :                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     435           0 :                 goto final;
     436             :         }
     437           0 :         if(!(colsBAT = (BAT**)GDKzalloc(sizeof(BAT*)*colsNum))) {
     438           0 :                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     439           0 :                 goto unfree2;
     440             :         }
     441           0 :         field_definitions = GDALWGetSimpleFieldDefinitions(shp_conn);
     442           0 :         for(i = 0; i < colsNum - 2; i++) {
     443           0 :                 cols[i] = NULL;
     444             :                 /* bind the column */
     445           0 :                 nameToLowerCase = toLower(field_definitions[i].fieldName);
     446           0 :                 cols[i] = mvc_bind_column(m, data_table, nameToLowerCase);
     447           0 :                 GDKfree(nameToLowerCase);
     448           0 :                 if(cols[i] == NULL) {
     449           0 :                         msg = createException(MAL, "shp.import", SQLSTATE(42SO2) "Column '%s.%s(%s)' missing", sch_name, data_table_name, field_definitions[i].fieldName);
     450           0 :                         goto unfree4;
     451             :                 }
     452             :                 /*create the BAT */
     453           0 :                 if (strcmp(field_definitions[i].fieldType, "Integer") == 0) {
     454           0 :                         if(!(colsBAT[i] = COLnew(0, TYPE_int, rowsNum, PERSISTENT))) {
     455           0 :                                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     456           0 :                                 goto unfree4;
     457             :                         }
     458           0 :                 } else if (strcmp(field_definitions[i].fieldType, "Real") == 0) {
     459           0 :                         if(!(colsBAT[i] = COLnew(0, TYPE_dbl, rowsNum, PERSISTENT))) {
     460           0 :                                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     461           0 :                                 goto unfree4;
     462             :                         }
     463             : #if 0
     464             :                 } else if (strcmp(field_definitions[i].fieldType, "Date") == 0) {
     465             :                         if(!(colsBAT[i] = COLnew(0, TYPE_str, rowsNum, PERSISTENT))) {
     466             :                                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     467             :                                 goto unfree4;
     468             :                         }
     469             : #endif
     470             :                 } else {
     471           0 :                         if(!(colsBAT[i] = COLnew(0, TYPE_str, rowsNum, PERSISTENT))) {
     472           0 :                                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     473           0 :                                 goto unfree4;
     474             :                         }
     475             :                 }
     476             :         }
     477           0 :         if(!(cols[colsNum - 2] = mvc_bind_column(m, data_table, "gid"))) {
     478           0 :                 msg = createException(MAL, "shp.import", SQLSTATE(42SO2) "Column '%s.%s(gid)' missing", sch_name, data_table_name);
     479           0 :                 goto unfree4;
     480             :         }
     481           0 :         if(!(colsBAT[colsNum - 2] = COLnew(0, TYPE_int, rowsNum, PERSISTENT))) {
     482           0 :                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     483           0 :                 goto unfree4;
     484             :         }
     485           0 :         if(!(cols[colsNum - 1] = mvc_bind_column(m, data_table, "geom"))) {
     486           0 :                 msg = createException(MAL, "shp.import", SQLSTATE(42SO2) "Column '%s.%s(geom)' missing", sch_name, data_table_name);
     487           0 :                 goto unfree4;
     488             :         }
     489           0 :         if(!(colsBAT[colsNum - 1] = COLnew(0, ATOMindex("wkb"), rowsNum, PERSISTENT))) {
     490           0 :                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     491           0 :                 goto unfree4;
     492             :         }
     493             : 
     494             :         /* import the data */
     495           0 :         featureDefn = OGR_L_GetLayerDefn(shp_conn.layer);
     496           0 :         OGR_L_ResetReading(shp_conn.layer);
     497           0 :         while((feature = OGR_L_GetNextFeature(shp_conn.layer)) != NULL ) {
     498             :                 wkb *geomWKB;
     499             :                 int len;
     500           0 :                 int gidTemp = ++gidNum;
     501             :                 gdk_return rc;
     502             : 
     503           0 :                 OGRGeometryH geometry = OGR_F_GetGeometryRef(feature);
     504             : 
     505           0 :                 for(i = 0; i < colsNum - 2; i++) {
     506           0 :                         hFieldDefn = OGR_FD_GetFieldDefn( featureDefn, i );
     507           0 :                         if( OGR_Fld_GetType(hFieldDefn) == OFTInteger ) {
     508           0 :                                 int val = OGR_F_GetFieldAsInteger(feature, i);
     509           0 :                                 rc = BUNappend(colsBAT[i], &val, false);
     510           0 :                         } else if( OGR_Fld_GetType(hFieldDefn) == OFTReal ) {
     511           0 :                                 double val = OGR_F_GetFieldAsDouble(feature, i);
     512           0 :                                 rc = BUNappend(colsBAT[i], &val, false);
     513             :                         } else {
     514           0 :                                 rc = BUNappend(colsBAT[i], OGR_F_GetFieldAsString(feature, i), false);
     515             :                         }
     516           0 :                         if (rc != GDK_SUCCEED) {
     517           0 :                                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     518           0 :                                 goto unfree4;
     519             :                         }
     520             :                 }
     521           0 :                 if (BUNappend(colsBAT[colsNum - 2], &gidTemp, false) != GDK_SUCCEED) {
     522           0 :                         msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     523           0 :                         goto unfree4;
     524             :                 }
     525             : 
     526           0 :                 len = OGR_G_WkbSize(geometry);
     527           0 :                 if (!(geomWKB = GDKmalloc(sizeof(wkb) - 1 + len))) {
     528           0 :                         msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     529           0 :                         OGR_F_Destroy(feature);
     530           0 :                         goto unfree4;
     531             :                 }
     532           0 :                 geomWKB->len = len;
     533           0 :                 geomWKB->srid = 0; //FIXME: Add the real srid
     534           0 :                 OGR_G_ExportToWkb(geometry, wkbNDR, (unsigned char *)geomWKB->data);
     535           0 :                 rc = BUNappend(colsBAT[colsNum - 1], geomWKB, false);
     536           0 :                 GDKfree(geomWKB);
     537           0 :                 OGR_F_Destroy(feature);
     538           0 :                 if (rc != GDK_SUCCEED)
     539           0 :                         goto unfree4;
     540             :         }
     541             : 
     542             :         /* finalise the BATs */
     543           0 :         if (store->storage_api.claim_tab(m->session->tr, data_table, BATcount(colsBAT[0]), &offset, &pos) != LOG_OK) {
     544           0 :                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     545           0 :                 goto unfree4;
     546             :         }
     547           0 :         if (!isNew(data_table) && sql_trans_add_dependency_change(m->session->tr, data_table->base.id, dml) != LOG_OK) {
     548           0 :                 bat_destroy(pos);
     549           0 :                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     550           0 :                 goto unfree4;
     551             :         }
     552           0 :         for(i = 0; i < colsNum; i++) {
     553           0 :                 if (store->storage_api.append_col(m->session->tr, cols[i], offset, pos, colsBAT[i], BATcount(colsBAT[0]), TYPE_bat) != LOG_OK) {
     554           0 :                         bat_destroy(pos);
     555           0 :                         msg = createException(MAL, "shp.import", SQLSTATE(38000) "Geos append column failed");
     556           0 :                         goto unfree4;
     557             :                 }
     558             :         }
     559           0 :         bat_destroy(pos);
     560             : 
     561             :         /* free the memory */
     562           0 : unfree4:
     563           0 :         for(i = 0; i < colsNum; i++) {
     564           0 :                 if (colsBAT[i])
     565           0 :                         BBPunfix(colsBAT[i]->batCacheid);
     566             :         }
     567           0 :         free(field_definitions);
     568           0 :         GDKfree(colsBAT);
     569           0 : unfree2:
     570           0 :         GDKfree(cols);
     571           0 : final:
     572           0 :         GDALWClose(shp_conn_ptr);
     573             : 
     574           0 :         return msg;
     575             : }
     576             : 
     577             : #if 0
     578             : str
     579             : SHPpartialimport(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) {
     580             :         size_t pos = 0;
     581             :         mvc *m = NULL;
     582             :         sql_schema *sch = NULL;
     583             :         char *sch_name = "sys";
     584             : 
     585             :         sql_table *shps_table = NULL, *fls_table = NULL, *data_table = NULL;
     586             :         char *shps_table_name = "shapefiles";
     587             :         char *fls_table_name = "files";
     588             :         char *data_table_name = NULL;
     589             : 
     590             :         sql_column *col;
     591             : 
     592             :         sql_column **cols;
     593             :         BAT **colsBAT;
     594             :         int colsNum = 2; //we will have at least the gid column and a geometry column
     595             :         int rowsNum = 0; //the number of rows in the shape file that will be imported
     596             :         int gidNum = 0;
     597             :         char *nameToLowerCase = NULL;
     598             : 
     599             :         str msg = MAL_SUCCEED;
     600             :         str fname = NULL;
     601             :         int vid = *(int*)getArgReference(stk, pci, 1);
     602             :         ptr* p = (ptr*)getArgReference(stk, pci, 2);
     603             :         wkb *g = (wkb*)*p;
     604             :         OGRGeometryH geom;
     605             :         OGREnvelope *mbb;
     606             :         /* SHP-level descriptor */
     607             :         OGRFieldDefnH hFieldDefn;
     608             :         int  i=0;
     609             :         oid irid;
     610             :         GDALWConnection shp_conn;
     611             :         GDALWConnection * shp_conn_ptr = NULL;
     612             :         GDALWSimpleFieldDef * field_definitions;
     613             :         OGRFeatureH feature;
     614             :         OGRFeatureDefnH featureDefn;
     615             :         gdk_return rc;
     616             : 
     617             :         /* calculate the mbb of the query geometry */
     618             :         geom = OGR_G_CreateGeometry(wkbPolygon);
     619             :         if (OGR_G_ImportFromWkb(geom, (unsigned char*)g->data, g->len) != OGRERR_NONE)
     620             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Could not intantiate the query polygon.");
     621             :         if (!(mbb = (OGREnvelope*)GDKmalloc(sizeof(OGREnvelope))))
     622             :                 return createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     623             :         OGR_G_GetEnvelope(geom, mbb);
     624             :         //FIXME: Take into account the coordinate reference system
     625             : 
     626             :         /* get table columns from shp and create the table */
     627             : 
     628             :         if((msg = getSQLContext(cntxt, mb, &m, NULL)) != MAL_SUCCEED)
     629             :                 return msg;
     630             :         if((msg = checkSQLContext(cntxt)) != MAL_SUCCEED)
     631             :                 return msg;
     632             : 
     633             :         if(!(sch = mvc_bind_schema(m, sch_name)))
     634             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Schema '%s' missing", sch_name);
     635             : 
     636             :         sqlstore *store = m->session->tr->store;
     637             :         /* find the name of the shape file corresponding to the given id */
     638             :         if(!(fls_table = mvc_bind_table(m, sch, fls_table_name)))
     639             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Table '%s.%s' missing", sch_name, fls_table_name);
     640             :         if(!(col = mvc_bind_column(m, fls_table, "id")))
     641             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(id)' missing", sch_name, fls_table_name);
     642             :         irid = store->table_api.column_find_row(m->session->tr, col, (void *)&vid, NULL);
     643             :         if (is_oid_nil(irid))
     644             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Shapefile with id %d not in the %s.%s table\n", vid, sch_name, fls_table_name);
     645             :         if(!(col = mvc_bind_column(m, fls_table, "path")))
     646             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(path)' missing", sch_name, fls_table_name);
     647             :         fname = (str)store->table_api.column_find_value(m->session->tr, col, irid);
     648             : 
     649             :         /* find the name of the table that has been reserved for this shape file */
     650             :         if(!(shps_table = mvc_bind_table(m, sch, shps_table_name)))
     651             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Table '%s.%s' missing", sch_name, shps_table_name);
     652             :         if(!(col = mvc_bind_column(m, shps_table, "fileid")))
     653             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(fileid)' missing", sch_name, shps_table_name);
     654             :         irid = store->table_api.column_find_row(m->session->tr, col, (void *)&vid, NULL);
     655             :         if (is_oid_nil(irid))
     656             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Shapefile with id %d not in the Shapefile catalog\n", vid);
     657             :         if(!(col = mvc_bind_column(m, shps_table, "datatable")))
     658             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(datatable)' missing", sch_name, shps_table_name);
     659             :         data_table_name = (str)store->table_api.column_find_value(m->session->tr, col, irid);
     660             : 
     661             : 
     662             :         /* add the data on the file to the table */
     663             : 
     664             :         if(!(shp_conn_ptr = GDALWConnect((char *) fname)))
     665             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Missing shape file %s\n", fname);
     666             :         shp_conn = *shp_conn_ptr;
     667             : 
     668             :         /*count the number of lines in the shape file */
     669             :         /* is there a better way to get this size? */
     670             :         OGR_L_ResetReading(shp_conn.layer);
     671             :         while( (feature = OGR_L_GetNextFeature(shp_conn.layer)) != NULL )
     672             :                 rowsNum++;
     673             : 
     674             :         /* bind the columns of the data file that was just created
     675             :         * and create a BAT for each of the columns */
     676             :         if(!(data_table = mvc_bind_table(m, sch, data_table_name)))
     677             :                 return createException(MAL, "shp.import", SQLSTATE(38000) "Table '%s.%s' missing", sch_name, data_table_name);
     678             :         colsNum += shp_conn.numFieldDefinitions;
     679             :         if(!(cols = (sql_column**)GDKmalloc(sizeof(sql_column*)*colsNum)))
     680             :                         return createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     681             :         if(!(colsBAT = (BAT**)GDKzalloc(sizeof(BAT*)*colsNum)))
     682             :                         return createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     683             :         field_definitions = GDALWGetSimpleFieldDefinitions(shp_conn);
     684             :         for(i = 0; i < colsNum - 2; i++) {
     685             :                 cols[i] = NULL;
     686             :                 /* bind the column */
     687             :                 nameToLowerCase = toLower(field_definitions[i].fieldName);
     688             :                 if(!(cols[i] = mvc_bind_column(m, data_table, nameToLowerCase)))
     689             :                         return createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(%s)' missing", sch_name, data_table_name, field_definitions[i].fieldName);
     690             :                 GDKfree(nameToLowerCase);
     691             :                 /*create the BAT */
     692             :                 if (strcmp(field_definitions[i].fieldType, "Integer") == 0) {
     693             :                         if(!(colsBAT[i] = COLnew(0, TYPE_int, rowsNum, PERSISTENT))) {
     694             :                                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     695             :                                 goto bailout;
     696             :                         }
     697             :                 } else if (strcmp(field_definitions[i].fieldType, "Real") == 0) {
     698             :                         if(!(colsBAT[i] = COLnew(0, TYPE_dbl, rowsNum, PERSISTENT))) {
     699             :                                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     700             :                                 goto bailout;
     701             :                         }
     702             : #if 0
     703             :                 } else if (strcmp(field_definitions[i].fieldType, "Date") == 0) {
     704             :                         if(!(colsBAT[i] = COLnew(0, TYPE_str, rowsNum, PERSISTENT))) {
     705             :                                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     706             :                                 goto bailout;
     707             :                         }
     708             : #endif
     709             :                 } else {
     710             :                         if(!(colsBAT[i] = COLnew(0, TYPE_str, rowsNum, PERSISTENT))) {
     711             :                                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     712             :                                 goto bailout;
     713             :                         }
     714             :                 }
     715             :         }
     716             :         if(!(cols[colsNum - 2] = mvc_bind_column(m, data_table, "gid"))) {
     717             :                 msg = createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(gid)' missing", sch_name, data_table_name);
     718             :                 goto bailout;
     719             :         }
     720             :         if(!(colsBAT[colsNum - 2] = COLnew(0, TYPE_int, rowsNum, PERSISTENT))) {
     721             :                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     722             :                 goto bailout;
     723             :         }
     724             :         if(!(cols[colsNum - 1] = mvc_bind_column(m, data_table, "geom"))) {
     725             :                 msg = createException(MAL, "shp.import", SQLSTATE(38000) "Column '%s.%s(geom)' missing", sch_name, data_table_name);
     726             :                 goto bailout;
     727             :         }
     728             :         if(!(colsBAT[colsNum - 1] = COLnew(0, ATOMindex("wkb"), rowsNum, PERSISTENT))) {
     729             :                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     730             :                 goto bailout;
     731             :         }
     732             : 
     733             :         /* apply the spatial filter */
     734             :         OGR_L_SetSpatialFilterRect(shp_conn.layer, mbb->MinX, mbb->MinY, mbb->MaxX, mbb->MaxY);
     735             :         /* import the data */
     736             :         featureDefn = OGR_L_GetLayerDefn(shp_conn.layer);
     737             :         OGR_L_ResetReading(shp_conn.layer);
     738             :         while( (feature = OGR_L_GetNextFeature(shp_conn.layer)) != NULL ) {
     739             :                 wkb *geomWKB;
     740             :                 int len;
     741             :                 int gidTemp = ++gidNum;
     742             : 
     743             :                 OGRGeometryH geometry = OGR_F_GetGeometryRef(feature);
     744             : 
     745             :                 for(i = 0; i < colsNum - 2; i++) {
     746             :                         hFieldDefn = OGR_FD_GetFieldDefn( featureDefn, i );
     747             :                         if( OGR_Fld_GetType(hFieldDefn) == OFTInteger ) {
     748             :                                 int val = OGR_F_GetFieldAsInteger(feature, i);
     749             :                                 rc = BUNappend(colsBAT[i], &val, false);
     750             :                         } else if( OGR_Fld_GetType(hFieldDefn) == OFTReal ) {
     751             :                                 double val = OGR_F_GetFieldAsDouble(feature, i);
     752             :                                 rc = BUNappend(colsBAT[i], &val, false);
     753             :                         } else if( OGR_Fld_GetType(hFieldDefn) == OFTString ) {
     754             :                                 rc = BUNappend(colsBAT[i], OGR_F_GetFieldAsString(feature, i), false);
     755             :                         } else {
     756             :                                 rc = BUNappend(colsBAT[i], OGR_F_GetFieldAsString(feature, i), false);
     757             :                         }
     758             :                         if (rc != GDK_SUCCEED) {
     759             :                                 msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     760             :                                 goto bailout;
     761             :                         }
     762             :                 }
     763             : 
     764             :                 if (BUNappend(colsBAT[colsNum - 2], &gidTemp, false) != HY013) {
     765             :                         msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     766             :                         goto bailout;
     767             :                 }
     768             : 
     769             :                 len = OGR_G_WkbSize(geometry);
     770             :                 if (!(geomWKB = GDKmalloc(sizeof(wkb) - 1 + len)))
     771             :                         return createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     772             :                 geomWKB->len = len;
     773             :                 geomWKB->srid = 0; //TODO: Add the real srid
     774             :                 OGR_G_ExportToWkb(geometry, wkbNDR, (unsigned char *)geomWKB->data);
     775             :                 if (BUNappend(colsBAT[colsNum - 1], geomWKB, false) != GDK_SUCCEED) {
     776             :                         msg = createException(MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     777             :                         goto bailout;
     778             :                 }
     779             :         }
     780             : 
     781             :         /* finalise the BATs */
     782             :         if (store->storage_api.claim_tab(m->session->tr, data_table, BATcount(colsBAT[0]), &offset, &pos) != LOG_OK) {
     783             :                 msg = createException(MAL, "shp.import", SQLSTATE(38000) "append_col failed");
     784             :                 goto bailout;
     785             :         }
     786             :         if (!isNew(data_table) && sql_trans_add_dependency_change(m->session->tr, data_table->base.id, dml) != LOG_OK) {
     787             :                 msg = createException((MAL, "shp.import", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     788             :                 goto bailout;
     789             :         }
     790             :         for(i = 0; i < colsNum; i++) {
     791             :                 if (store->storage_api.append_col(m->session->tr, cols[i], offset, pos, colsBAT[i], BATcount(colsBAT[0]), TYPE_bat) != LOG_OK) {
     792             :                         msg = createException(MAL, "shp.import", SQLSTATE(38000) "append_col failed");
     793             :                         goto bailout;
     794             :                 }
     795             :         }
     796             : 
     797             :   bailout:
     798             :         for(i = 0; i < colsNum; i++) {
     799             :                 if (colsBAT[i])
     800             :                         BBPunfix(colsBAT[i]->batCacheid);
     801             :         }
     802             : 
     803             :         /* free the memory */
     804             :         GDKfree(cols);
     805             :         GDKfree(colsBAT);
     806             :         OGR_G_DestroyGeometry(geom);
     807             : 
     808             :         free(field_definitions);
     809             :         GDALWClose(shp_conn_ptr);
     810             : 
     811             :         return msg;
     812             : 
     813             : }
     814             : #endif
     815             : 
     816             : str
     817           0 : SHPimport(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) {
     818           0 :         return SHPimportFile(cntxt, mb, stk, pci, false);
     819             : }
     820             : 
     821             : str
     822           0 : SHPpartialimport(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) {
     823           0 :         return SHPimportFile(cntxt, mb, stk, pci, true);
     824             : }
     825             : 
     826             : #include "mel.h"
     827             : static mel_func shp_init_funcs[] = {
     828             :  pattern("shp", "attach", SHPattach, false, "Register an ESRI Shapefile in the vault catalog", args(1,2, arg("",void),arg("filename",str))),
     829             :  pattern("shp", "import", SHPimport, false, "Import an ESRI Shapefile with given id into the vault", args(1,2, arg("",void),arg("fileid",int))),
     830             :  pattern("shp", "import", SHPpartialimport, false, "Partially import an ESRI Shapefile with given id into the vault", args(1,3, arg("",void),arg("fileid",int),arg("po",wkb))),
     831             :  { .imp=NULL }
     832             : };
     833             : #include "mal_import.h"
     834             : #ifdef _MSC_VER
     835             : #undef read
     836             : #pragma section(".CRT$XCU",read)
     837             : #endif
     838         254 : LIB_STARTUP_FUNC(init_shp_mal)
     839         254 : { mal_module("shp", NULL, shp_init_funcs); }

Generated by: LCOV version 1.14