Index: src/spatial/cpp/metacat_shapefile.cpp
===================================================================
--- src/spatial/cpp/metacat_shapefile.cpp	(nonexistent)
+++ src/spatial/cpp/metacat_shapefile.cpp	(revision 2564)
@@ -0,0 +1,245 @@
+/** ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
+****************************************************************************
+ Copyright (C) 2001 Numeric Solutions.  All Rights Reserved.
+
+  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+
+Further, this software is distributed without any warranty that it is
+ free of the rightful claim of any third person regarding infringement
+ or the like.  Any license provided herein, whether implied or
+ otherwise, applies only to this software file.  Patent licenses, if
+ any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever.
+
+You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+  Contact information: Numeric Solutions support@numericsolutions.com, or:
+
+http://www.numericsolutions.com
+
+fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff */
+
+
+#include "shapefil.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "iostream.h"
+
+#include <fstream>
+#include <string>
+#include <vector>
+
+using namespace std;
+
+
+/************************************************************************
+ * Method to write the points array to the shape file and the associated
+ * dbf file using the shapelib-1.2.xx libraries
+ *
+ * @param nSHPType -- the type of shapefile (eg. poly vs point )
+ *
+ * @param pszFilename -- the name of the shape file, sans the extension
+ *
+ * @param gridx -- this is the float value of the x-location (assuming points)
+ *
+ * @param gridy -- this is the float value of the y-location (assuming points)
+ *
+ * @param gridz -- this is the float value of the optional p-value
+ * (assuming points)
+ *
+ * @param the number of lines in the coordinates arrays
+ ************************************************************************/
+static void WritePointsArray ( int nSHPType, const char * pszFilename,
+  float gridx[40000] [100], float gridy[40000] [100],float gridz[40000] [100],
+  vector<string> urlvec, vector<string> docidvec, int number_data_lines ) {
+
+       SHPHandle hSHPHandle;
+       SHPObject * psShape;
+       double x, y, z, m, j, dx[number_data_lines], dy[number_data_lines], dz[number_data_lines];
+       int ii, iRecord, i;
+       char buf[20];
+       char intString;
+       //for the dbf file
+       DBFHandle hDBF;
+
+       //create the dbf file
+       hDBF = DBFCreate( pszFilename );
+       if ( hDBF == NULL )
+       {
+         printf( "DBFCreate(%s) failed.\n" );
+         exit( 2 );
+       }
+
+       //add to the dbf file attributes for ID, pval(elevation), url
+       if ( DBFAddField( hDBF, "ID", FTDouble, 10, 10 ) == -1 )
+       {
+         printf( "DBFAddField(%s,FTDouble,%d,0) failed.\n" );
+       }
+       if ( DBFAddField( hDBF, "pval", FTDouble, 10, 10 ) == -1 )
+       {
+         printf( "DBFAddField(%s,FTDouble,%d,0) failed.\n" );
+       }
+       if ( DBFAddField( hDBF, "url", FTString, 220, 0 ) == -1 )
+       {
+         printf( "DBFAddField(%s,FTString,%d,0) failed.\n" );
+       }
+       if ( DBFAddField( hDBF, "docid", FTString, 220, 0 ) == -1 )
+       {
+         printf( "DBFAddField(%s,FTString,%d,0) failed.\n" );
+       }
+
+
+      //cout<<" DBF Record Count --> "<<iRecord<<endl;
+      int id_field = DBFGetFieldIndex( hDBF, "ID" );
+      int pval_field = DBFGetFieldIndex( hDBF, "pval" );
+      int url_field = DBFGetFieldIndex( hDBF, "url" );
+      int docid_field = DBFGetFieldIndex( hDBF, "docid" );
+
+      //cout << "id field -> " << id_field << endl;
+      //cout << "pval field -> " << pval_field << endl;
+      //cout << "url field -> " << url_field << endl;
+
+
+      hSHPHandle = SHPCreate( pszFilename, nSHPType );
+
+       ii = 0;
+       for ( ii = 0; ii < number_data_lines; ii++ )
+       {
+         double xx = ( gridx[2] [ii] );
+         double yy = ( gridy[2] [ii] );
+         double zz = ( gridz[2] [ii] );
+
+         //if (xx < 180 && xx > -180 && yy < 90 && yy >-90 ) {
+
+         psShape = SHPCreateObject( SHPT_POINT, ii, 0, NULL, NULL, 1, &xx, &yy, &zz, NULL );
+
+         SHPWriteObject( hSHPHandle, -1, psShape );
+         SHPDestroyObject( psShape );
+         //do the update to the dbf file too
+         iRecord = DBFGetRecordCount( hDBF );
+
+
+        DBFWriteStringAttribute(hDBF, iRecord, url_field, urlvec[ii].c_str() );
+        DBFWriteStringAttribute(hDBF, iRecord, docid_field, docidvec[ii].c_str() );
+        DBFWriteDoubleAttribute(hDBF, iRecord, pval_field, 999 );
+        DBFWriteDoubleAttribute(hDBF, iRecord, id_field, ii );
+       //  }
+       }
+       //recompute the extents
+       //SHPComputeExtents( psShape );
+       //cout << "xmin: " << psShape->dfXMin << " xmax: " << psShape->dfXMax << endl;
+       //cout << "ymin: " << psShape->dfYMin << " ymax: " << psShape->dfYMax << endl;
+       DBFClose( hDBF );
+       SHPClose( hSHPHandle );
+}
+
+
+/** getUsage -- function that prints to stdout the usage for this driver */
+void getUsage()
+{
+  cout<<"usage: metacat2shape metacat_export.txt test.shp
+
+    where:
+            input -- is an input ASCII file, that contains the following cols:
+             -> docid -- the document id
+             -> x -- the xlocation
+             -> y -- the y location
+             -> url -- the url to the document
+
+            shapefile -- {output} is a ESRI shapefile
+
+    see:
+    example: metacat2shape metacat_export.txt test.shp
+
+    ##><><><><><><><><><><><><><><><><><><><><><><><><>##
+    ##           John Harris                           ##
+    ##           harris@nceas.ucsb.edu                 ##
+    ##           Copyright 1999-2003                   ##
+    ##><><><><><><><><><><><><><><><><><><><><><><><><>##
+    "<<endl;
+
+}
+
+
+
+int main( int argc, char * * argv )
+{
+  //get the usage info if the inputs are not right
+  if ( argc != 3 )
+  {
+    getUsage();
+    exit( 1 );
+  }
+
+  //these arrays are for the input x, y, z data
+  float gridx[1000] [100];
+  float gridy[1000] [100];
+  float gridz[1000] [100];
+  vector<string> docidvec;
+  vector<string> urlvec;
+
+  FILE * infile;
+  char oneline[200];
+  char * value;
+
+  int cnt = 0;
+  int number_lines = 0;
+  char bufa[100];
+  char buf[100];
+  char buf1[100];
+  char buf2[100];
+
+  SHPHandle hSHP;
+  int nShapeType, nEntities, i, iPart;
+  const char * pszPlus;
+
+  //test the reading of the file
+  if ( ( infile = fopen( argv[1], "r" ) ) == ( FILE * ) NULL )
+  {
+    fprintf( stderr, "Can't read the file: %s.\n", argv[1] );
+    exit( 2 );
+  }
+
+  /* read the data into an array -- first the grid nodes */
+  infile = fopen( argv[1], "r" );
+  char const * out_shape = argv[2];
+  while ( fgets( oneline, 199, infile ) ) {
+    sscanf( oneline, "%s %s %s %s", bufa, buf, buf1, buf2 );
+
+    /**** cout<<" docid -> " << bufa
+      <<"\n cnt -> " << cnt
+      <<"\n x -> " << buf
+      <<"\n y -> " << buf1
+      <<"\n p -> " << buf2
+      <<endl; *******/
+
+    gridx[2] [cnt] = atof( buf );
+    gridy[2] [cnt] = atof( buf1 );
+    gridz[2] [cnt] = atof( buf2 );
+    //char const * sLine = buf2;
+    urlvec.push_back(buf2);
+    docidvec.push_back(bufa);
+    cnt++;
+    number_lines = cnt;
+  }
+  fclose( infile );
+
+  cout<<"creating a new shape file, with "<< number_lines <<" records "<<endl;
+  WritePointsArray( SHPT_POINT, out_shape, gridx, gridy, gridz,
+                    urlvec, docidvec, number_lines );
+
+#ifdef USE_DBMALLOC
+  malloc_dump( 2 );
+#endif
+  exit( 0 );
+}

Property changes on: src/spatial/cpp/metacat_shapefile.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: bin/metacat_shapefile
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
