コード例 #1
0
ファイル: vpfdraw.c プロジェクト: LucHermitte/ossim
/*************************************************************************
 *
 *N  draw_text_row
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *     This function draws annotation for a given row in the text
 *     pseudo-primitive table.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     row         <input>==(row_type) row of the text table.
 *     table       <input>==(vpf_table_type) text primitive table.
 *     return     <output>==(int) 0 if the user escapes, 1 upon successful
 *                          completion.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   August 1991                        DOS Turbo C
 *E
 *************************************************************************/
int draw_text_row( row_type row, vpf_table_type table )
{
   int xscr,yscr, shape_pos, text_pos;
   ossim_int32 n, nshape;
   coordinate_type *shape_line;
   char *text;
   struct viewporttype vp;

   shape_pos = table_pos("SHAPE_LINE",table);
/**** MUST CHECK FOR 'Z', 'B', AND 'Y' TYPES - SEE VPFPRIM.C ****/
   shape_line = (coordinate_type *)get_table_element(shape_pos,row,table,
						     NULL,&nshape);
   text_pos = table_pos("STRING",table);
   text = (char *)get_table_element(text_pos,row,table,NULL,&n);

   screenxy(shape_line[0].x,shape_line[0].y,&xscr,&yscr);

   getviewsettings(&vp);
   if ((gpgetfont() != DEFAULT_FONT) || (yscr > gptextheight(text))) {
      hidemousecursor();
      gptext(xscr,yscr,text);
      showmousecursor();
   }

   free(shape_line);
   free(text);

   while (kbhit()) {
      if (getch()==27) {
	 return 0;
      }
   }

   return 1;
}
コード例 #2
0
/**************************************************************************
 *
 *N  related_row
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Return the related row of table2 based upon the value of table 1's key
 *    Table 2 must be the '1' side of an n:1 relationship  --  If it isn't,
 *    use 'related_rows()'.
 *    Supported data types - I and T<n>.
 *    Binary search supported only for data type I. (column must be sorted)
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
long int related_row( void *keyval1,
		      vpf_table_type table2, char *key2,
		      int sort_flag )
{
   long int rowid, i, ival, kval, n;
   row_type row;
   int KEY2_;
   char cval, *tval;

   if (ossim_strcasecmp(key2,"ID")==0) {
      memcpy( &rowid, keyval1, sizeof(rowid) );
      return rowid;
   }

   rowid = 0;

   KEY2_ = table_pos(key2,table2);

   if ((table2.header[KEY2_].type != 'I')&&
       (table2.header[KEY2_].type != 'T')) return rowid;

   if ((table2.header[KEY2_].type == 'I')&&
       (table2.header[KEY2_].count != 1)) return rowid;

   if ((table2.header[KEY2_].type == 'T')&&(sort_flag)) sort_flag = 0;

   if (table2.header[KEY2_].type == 'I') memcpy(&kval,keyval1,sizeof(kval));

   if (!sort_flag) {   /* Sequential search */

      for (i=1;i<=table2.nrows;i++) {
	 row = get_row(i,table2);
	 if (table2.header[KEY2_].type == 'I') {
	    get_table_element(KEY2_,row,table2,&ival,&n);
	    if (ival == kval) rowid = i;
	 } else {
	    if (table2.header[KEY2_].count==1) {
	       get_table_element(KEY2_,row,table2,&cval,&n);
	       if (memcmp(&cval,keyval1,sizeof(ival))==0) rowid = i;
	    } else {
	       tval = (char*)get_table_element(KEY2_,row,table2,NULL,&n);
	       if (strcmp(tval,(char *)keyval1)==0) rowid = i;
	    }
	 }
	 free_row(row,table2);
	 if (rowid > 0) break;
      }

   } else {   /* Binary search */

      memcpy(&kval,keyval1,sizeof(kval));
      rowid = vpf_binary_search( kval, KEY2_, table2 );

   }

   return rowid;
}
コード例 #3
0
ファイル: vpfselec.c プロジェクト: vapd-radi/rspf_v2.0
/*************************************************************************
 *
 *N  bounding_select
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    This function reads the bounding rectangle table to weed out the
 *    local primitives.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    path      <input> == (char *) path to the bounding rectangle table.
 *    mapextent <input> == (extent_type) map extent to compare.
 *    dec_degrees <input> == (int) flag to indicate if data is in decimal
 *                                 degrees.
 *    bounding_select <output> == (set_type) set of bounding rectangle ids.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   May 1991                           DOS Turbo C
 *E
 *************************************************************************/
set_type bounding_select( char *path, extent_type mapextent,
			  int dec_degrees )
{
   vpf_table_type table;
   set_type set;
   rspf_int32 i, count;
   extent_type box, pextent;
   double x1,y1,x2,y2;
   row_type row;
   int XMIN_,YMIN_,XMAX_,YMAX_;

   /* Project all extents to plate-carree for cartesian comparisons */
   /* (decimal degree coordinate systems) */

   x1 = mapextent.x1; y1 = mapextent.y1;
   x2 = mapextent.x2; y2 = mapextent.y2;
   if (dec_degrees) {
      set_plate_carree_parameters( central_meridian(x1,x2), 0.0, 1.0 );
      pcarree_xy(&x1,&y1);
      pcarree_xy(&x2,&y2);
   }
   pextent.x1 = x1; pextent.y1 = y1;
   pextent.x2 = x2; pextent.y2 = y2;

   table = vpf_open_table(path,disk,"rb",NULL);
   XMIN_ = table_pos("XMIN",table);
   YMIN_ = table_pos("YMIN",table);
   XMAX_ = table_pos("XMAX",table);
   YMAX_ = table_pos("YMAX",table);
   set = set_init(table.nrows+1);
   for (i=1;i<=table.nrows;i++) {
      row = read_next_row(table);
      get_table_element(XMIN_,row,table,&box.x1,&count);
      get_table_element(YMIN_,row,table,&box.y1,&count);
      get_table_element(XMAX_,row,table,&box.x2,&count);
      get_table_element(YMAX_,row,table,&box.y2,&count);
      free_row(row,table);

      x1 = box.x1; y1 = box.y1;
      x2 = box.x2; y2 = box.y2;
      if (dec_degrees) {
	 pcarree_xy(&x1,&y1);
	 pcarree_xy(&x2,&y2);
      }
      box.x1 = x1; box.y1 = y1;
      box.x2 = x2; box.y2 = y2;

      if ( contained(box,pextent) || contained(pextent,box) ) {
	 set_insert(i,set);
      }
   }
   vpf_close_table(&table);

   return set;
}
コード例 #4
0
/**************************************************************************
 *
 *N  vpf_dump_doc_table
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Dump the contents of a narrative-style .DOC VPF table into an
 *    ASCII file as a series of text strings.  This function checks
 *    to make sure that the given table is a real narrative file
 *    (two fields: ID and TEXT).  If not, it displays it as a normal
 *    VPF table.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    tablename <input> == (char *) narrative-style .DOC VPF table to dump.
 *    outname   <input> == (char *) name of ASCII dump file.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
void vpf_dump_doc_table( char *tablename, char *outname )
{
   vpf_table_type table;
   long int   i,n;
   char       *buf;
   row_type   row;
   FILE       *fp;

   fp = fopen(outname,"w");

   table = vpf_open_table(tablename,disk,"rb",NULL);

   /* Check header to make sure the table is a narrative table */
   if ((ossim_strcasecmp(table.header[1].name,"TEXT") != 0) ||
       (table.nfields != 2)) {
      /* Not a real narrative table -> normal VPF table dump */
      vpf_close_table(&table);
      vpf_dump_table(tablename,outname);
      return;
   }

   fprintf(fp,"%s\n%s\n\n",tablename,table.description);

   for (i=1;i<=table.nrows;i++) {
      row = read_next_row(table);
      buf = (char *)get_table_element(1,row,table,NULL,&n);
      fprintf(fp,"%s\n",buf);
      free(buf);
      free_row(row,table);
   }

   fclose(fp);
   vpf_close_table( &table );
}
コード例 #5
0
/**************************************************************************
 *
 *N  vpf_binary_search
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    This function performs a binary search on a VPF table for the
 *    specified integer value.  Only VPF data type 'I' is supported.
 *    The table must be sorted on the specified field, or this function
 *    will give unpredictable results.  The table must have been
 *    successfully opened.  If more than one row matches the search
 *    value, only the first encountered will be returned.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    srchval <input> == (long int) specified search value.
 *    field   <input> == (int) table sort field.
 *    table   <input> == (vpf_table_type) VPF table.
 *    vpf_binary_search <output> == (long int) first matching row.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
long int vpf_binary_search( long int srchval,
			    int field,
			    vpf_table_type table )
{
   long int left,right, ival, rowid, n;
   row_type row;

   left = 1;
   right = table.nrows;

   do {
      rowid = (left+right)/2;
      row = get_row(rowid,table);
      get_table_element(field,row,table,&ival,&n);
      free_row(row,table);
      if (ival < srchval)
	 right = rowid-1;
      else
	 left = rowid+1;
   } while ((srchval != ival) && (left <= right));

   if (srchval != ival) rowid = 0;

   return rowid;
}
コード例 #6
0
ファイル: vpfread.c プロジェクト: loongfee/ossim-svn
/* Compute the offset from the start of the row to the given field */
static ossim_int32 row_offset( int field, row_type row, vpf_table_type table)
{
   ossim_int32 offset,n,size;
   int i;
   id_triplet_type key;
   int keysize[] = {0,sizeof(char),sizeof(short int),sizeof(ossim_int32)};

   if (field < 0 || field >= table.nfields) return -1;

   offset = 0L;
   for (i=0;i<field;i++) {
      switch (table.header[i].type) {
	 case 'I':
	    offset += sizeof(ossim_int32)*row[i].count;
	    break;
	 case 'S':
	    offset += sizeof(short int)*row[i].count;
	    break;
	 case 'T':
	    offset += sizeof(char)*row[i].count;
	    break;
	 case 'F':
	    offset += sizeof(float)*row[i].count;
	    break;
	 case 'D':
	    offset += sizeof(date_type)*row[i].count;
	    break;
	 case 'K':
	    get_table_element(i,row,table,&key,&n);
	    size = sizeof(char) +
		   keysize[TYPE0(key.type)] +
		   keysize[TYPE1(key.type)] +
		   keysize[TYPE2(key.type)];
	    offset += size*row[i].count;
	    break;
	 case 'R':
	    offset += sizeof(double)*row[i].count;
	    break;
	 case 'C':
	    offset += sizeof(coordinate_type)*row[i].count;
	    break;
	 case 'B':
	    offset += sizeof(double_coordinate_type)*row[i].count;
	    break;
	 case 'Z':
	    offset += sizeof(tri_coordinate_type)*row[i].count;
	    break;
	 case 'Y':
	    offset += sizeof(double_tri_coordinate_type)*row[i].count;
	    break;
      }
   }
   return offset;
}
コード例 #7
0
ファイル: vpfread.c プロジェクト: loongfee/ossim-svn
/*************************************************************************
 *
 *N  table_element
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *     This function returns the element in the specified row in the column
 *     matching the given field number.  If the element is a single element
 *     (count=1), the value is passed back via the void pointer *value;
 *     otherwise, an array is allocated and passed back as the return value.
 *     NOTE: If an array is allocated in this function, it should be freed
 *     when no longer needed.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    field_number <input> == (ossim_int32) field number (offset from
 *                                   first field in table).
 *    row_number <input> == (ossim_int32) row_number.
 *    table      <input> == (vpf_table_type) VPF table structure.
 *    value     <output> == (void *) pointer to a single element value.
 *    count     <output> == (ossim_int32 *) pointer to the array size for a multiple
 *                                  element value.
 *    return    <output> == (void *) returned multiple element value or
 *                          NULL of the field number is invalid
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   May 1991                     DOS Turbo C
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   External Variables:
 *X
 *    None
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Functions Called:
 *F
 *    row_type get_row()                   VPFREAD.C
 *    void free_row()                      VPFREAD.C
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Portability:
 *O
 *    This module should be ANSI C compatible.
 *E
 *************************************************************************/
void *table_element( ossim_int32         field_number,
		     ossim_int32         row_number,
		     vpf_table_type   table,
		     void           * value,
		     ossim_int32       * count )
{
   row_type    row;
   void      * retvalue;

   row      = get_row(row_number, table);
   retvalue = get_table_element(field_number, row, table, value, count);
   free_row(row,table);

   return retvalue;
}
コード例 #8
0
ファイル: vpfdraw.c プロジェクト: LucHermitte/ossim
/*************************************************************************
 *
 *N  draw_point_row
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *     This function draws an entity node for the row in the given
 *     entity node primitive table.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     row         <input>==(row_type) row of the entity node
 *                          primitive table.
 *     table       <input>==(vpf_table_type) entity node primitive table.
 *     return     <output>==(int) 0 if the user escapes, 1 upon successful
 *                          completion.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   August 1991                        DOS Turbo C
 *E
 *************************************************************************/
int draw_point_row( row_type row, vpf_table_type table )
{
   int xscr,yscr, coord_pos;
   ossim_int32 n;
   coordinate_type pnt;

   coord_pos = table_pos("COORDINATE",table);
   get_table_element(coord_pos,row,table,&pnt,&n);

   screenxy(pnt.x,pnt.y,&xscr,&yscr);
   hidemousecursor();
   gpmarker(xscr,yscr);
   showmousecursor();

   while (kbhit()) {
      if (getch()==27) {
	 return 0;
      }
   }

   return 1;
}
コード例 #9
0
ファイル: trie.c プロジェクト: FunnyLanguage/funny
Queue *trie_find(Trie *trie, void *element) {
	TrieNode *node = trie->root;
	char *p = trie->findPrefixFunc(element);
	if (prefix_out_of_range(p)) {
		HashNode *hashNode = get_table_element(trie->table, p, hash_code_string);
		Queue *queue = init_queue();
		while (hashNode != NULL) {
			enqueue(queue, hashNode->element);
			hashNode = hashNode->next;
		}
		return queue;
	}

	int index;
	while (*p && node) {
		index = *p - BASE_CHAR;
		node = node->next[index];
		p++;
	}
	if (node == NULL)
		return NULL;
	return node->queue;
}
コード例 #10
0
ファイル: vpfread.c プロジェクト: loongfee/ossim-svn
/*************************************************************************
 *
 *N  named_table_element
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *     This function returns the element in the specified row in the column
 *     matching the given field name.  If the element is a single element
 *     (count=1), the value is passed back via the void pointer *value;
 *     otherwise, an array is allocated and passed back as the return value.
 *     NOTE: If an array is allocated in this function, it should be freed
 *     when no longer needed.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    field_name <input> == (char *) field name.
 *    row_number <input> == (ossim_int32) row_number.
 *    table      <input> == (vpf_table_type) VPF table structure.
 *    value     <output> == (void *) pointer to a single element value.
 *    count     <output> == (ossim_int32 *) pointer to the array size for a multiple
 *                                  element value.
 *    return    <output> == (void *) returned multiple element value.
 *                          or NULL if field_name could not be found
 *                          as a column
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   May 1991                     DOS Turbo C
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   External Variables:
 *X
 *    None
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Functions Called:
 *F
 *    void *vpfmalloc()                    VPFREAD.C
 *    row_type get_row()                   VPFREAD.C
 *    void free_row()                      VPFREAD.C
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Portability:
 *O
 *    This module should be ANSI C compatible.
 *E
 *************************************************************************/
void *named_table_element( char           * field_name,
			   ossim_int32         row_number,
			   vpf_table_type   table,
			   void           * value,
			   ossim_int32       * count )
{
   ossim_int32     col;
   row_type     row;
   void       * retvalue;

   col = table_pos(field_name, table);

   if (col < 0) {
      fprintf(stderr,"%s: Invalid field name <%s>\n",table.name,field_name);
      return NULL;
   }
   row = get_row(row_number,table);

   retvalue = get_table_element( col, row, table, value, count );

   free_row(row, table);

   return retvalue;
}
コード例 #11
0
/**************************************************************************
 *
 *N  related_rows
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Return the list of related rows of table2 based upon the value of
 *    table 1's key.
 *    Supported data types - I and T<n>.
 *    Binary search supported only for data type I. (column must be sorted)
 *    Thematic index used, if present on key column.
 *    NOTE: A sequential search operation will search the entire
 *          table ...zzz...
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
linked_list_type related_rows( void *keyval1,
		       vpf_table_type table2, char *key2,
		       int sort_flag,
		       ThematicIndex *idx )
{
   linked_list_type rowlist;
   set_type rowset;
   long int rowid, i, ival, kval, n, start,end;
   row_type row = 0;
   int KEY2_;
   char cval, *tval;

   rowlist = ll_init();

   if (ossim_strcasecmp(key2,"ID")==0) {
      memcpy( &rowid, keyval1, sizeof(rowid) );
      ll_insert(&rowid,sizeof(rowid),rowlist);
      return rowlist;
   }

   KEY2_ = table_pos(key2,table2);

   if ((table2.header[KEY2_].type != 'I')&&
       (table2.header[KEY2_].type != 'T')) return rowlist;

   if ((table2.header[KEY2_].type == 'I')&&
       (table2.header[KEY2_].count != 1)) return rowlist;

   if ((table2.header[KEY2_].type == 'T')&&(sort_flag)) sort_flag = 0;

   if (idx) {
      if (idx->fp) {
	 rowset = search_thematic_index(idx,(char *)keyval1);
	 start = set_min(rowset);
	 end = set_max(rowset);
	 for (i=start;i<=end;i++)
	    if (set_member(i,rowset)) {
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	    }
	 set_nuke(&rowset);
	 return rowlist;
      }
   }

   if (!sort_flag) {   /* Sequential search */

      for (i=1;i<=table2.nrows;i++) {
	 row = get_row(i,table2);
	 if (table2.header[KEY2_].type == 'I') {
	    get_table_element(KEY2_,row,table2,&ival,&n);
	    if (memcmp(&ival,keyval1,sizeof(ival))==0)
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	 } else {
	    if (table2.header[KEY2_].count==1) {
	       get_table_element(KEY2_,row,table2,&cval,&n);
	       if (memcmp(&cval,keyval1,sizeof(ival))==0)
		  ll_insert(&i,sizeof(i),ll_last(rowlist));
	    } else {
	       tval = (char*)get_table_element(KEY2_,row,table2,NULL,&n);
	       if (strcmp(tval,(char *)keyval1)==0)
		  ll_insert(&i,sizeof(i),ll_last(rowlist));
	    }
	 }
	 free_row(row,table2);
      }

   } else {   /* Binary search */

      memcpy(&kval,keyval1,sizeof(kval));
      rowid = vpf_binary_search( kval, KEY2_, table2 );

      if (rowid > 0) {
	 ll_insert(&rowid,sizeof(rowid),ll_last(rowlist));
	 i = rowid-1L;
	 do {
	    get_row(i,table2);
	    get_table_element(KEY2_,row,table2,&ival,&n);
	    if (ival == kval)
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	    i--;
	 } while ((ival==kval)&&(i>0));
	 i = rowid+1L;
	 do {
	    get_row(i,table2);
	    get_table_element(KEY2_,row,table2,&ival,&n);
	    if (ival == kval)
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	    i++;
	 } while ((ival==kval)&&(i<=table2.nrows));
      }

   }

   return rowlist;
}
コード例 #12
0
ファイル: vpfdisp.c プロジェクト: loongfee/ossim-svn
/*************************************************************************
 *
 *N  vpf_display_record
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *     This function displays all of the fields of a particular VPF
 *     record, including the descriptions of the fields and their
 *     values.  It accesses the online data dictionary metadata
 *     contained in the specified Value Description Tables.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    row     <input> == (row_type) vpf table row structure.
 *    table   <input> == (vpf_table_type) vpf table.
 *    fp      <input> == (FILE *) pointer to the output file.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels    Sept 1991                     DOS Turbo C
 *E
 *************************************************************************/
void vpf_display_record( row_type row,
			 vpf_table_type table,
			 FILE *fp )
{
   register int i,j;
   char *buf,*num, path[128], *tablename;
   char *attr,*val,*descr, vdtpath[128], fmtdate[40];
   vpf_table_type vdt;
   row_type vdtrow;
   int found;
   ossim_int32 l, lval, count, *lptr;
   short int s,sval,*sptr;
   float f,*fptr;
   date_type date;
   int TABLE_ = 1, ATTR_ = 2, VAL_ = 3, DESCR_ = 4;

   num = (char *)vpfmalloc(20*sizeof(char));

   strcpy( vdtpath, "" );

   /* Display all secondary attributes */
   for (i=0;i<table.nfields;i++) {
      switch (table.header[i].type) {
	 case 'T':
	    buf = (char *)get_table_element(i,row,table,
					    NULL,&count);
	    rightjust(buf);
	    if (strcmp( buf, "" ) != 0) {
	       fputs(table.header[i].name,fp);
	       fputs(" - ",fp);
	       fputs(table.header[i].description,fp);
	       fputs(": ",fp);
	       fputs(buf,fp);


	       strcpy( path, table.path );
	       strcat( path, table.header[i].vdt );
	       if ( (access(path,4)==0) &&
		    (strcmp(table.header[i].vdt,"") != 0) ) {

		  if (strcmp(vdtpath,path) != 0) {
		     if (strcmp(vdtpath,"") != 0) {
			vpf_close_table(&vdt);
		     }
		     vdt = vpf_open_table( path, disk, "rb", NULL );
		  }

		  strcpy( vdtpath, path );
		  for (j=1;j<=vdt.nrows;j++) {
		     vdtrow = read_row( j, vdt );
		     tablename = (char *)get_table_element( TABLE_, vdtrow,
							 vdt, NULL, &count );
		     rightjust(tablename);
		     strupr2(tablename);
		     attr = (char *)get_table_element( ATTR_, vdtrow, vdt,
						       NULL, &count );
		     rightjust(attr);
		     val = (char *)get_table_element( VAL_, vdtrow, vdt,
						      NULL, &count );
		     rightjust(val);

		     found = FALSE;
		     if ( (strstr(table.name,tablename)) &&
			  (ossim_strcasecmp(attr,table.header[i].name)==0) &&
			  (ossim_strcasecmp(val,buf)==0) ) {
			descr = (char *)get_table_element(DESCR_,vdtrow,vdt,
							  NULL, &count);
			rightjust(descr);
			fputs(" (",fp);
			fputs(descr,fp);
			fputs(")",fp);

			free(descr);
			found = TRUE;
		     }
		     free(tablename);
		     free(attr);
		     free(val);
		     free_row( vdtrow, vdt );
		     if (found) break;
		  }
	       }


	       fputc('\n',fp);
	    }
	    free(buf);
	    break;
	 case 'I':
	    if (table.header[i].count==1) {
	       get_table_element(i,row,table,&l,&count);
	       if (l != NULLINT) {
		  fputs(table.header[i].name,fp);
		  fputs(" - ",fp);
		  fputs(table.header[i].description,fp);
		  fputs(": ",fp);
		  ltoa((int)l,num,10);
		  fputs(num,fp);

		  strcpy( path, table.path );
		  strcat( path, table.header[i].vdt );
		  if ( (access(path,4)==0) &&
		     (strcmp(table.header[i].vdt,"") != 0) ) {

		     if (strcmp(vdtpath,path) != 0) {
			if (strcmp(vdtpath,"") != 0) {
			   vpf_close_table(&vdt);
			}
			vdt = vpf_open_table( path, disk, "rb", NULL );
		     }
		     strcpy( vdtpath, path );

		     for (j=1;j<=vdt.nrows;j++) {
			vdtrow = read_row( j, vdt );
			tablename = (char *)get_table_element( TABLE_,
					      vdtrow, vdt, NULL, &count );
			rightjust(tablename);
			strupr2(tablename);
			attr = (char *)get_table_element( ATTR_, vdtrow, vdt,
							  NULL, &count );
			rightjust(attr);
			get_table_element( VAL_, vdtrow, vdt,
					   &lval, &count );

			found = FALSE;
			if ( (strstr(table.name,tablename)) &&
			   (ossim_strcasecmp(attr,table.header[i].name)==0) &&
			   (lval==l) ) {
			   descr = (char *)get_table_element(DESCR_,vdtrow,
							 vdt, NULL, &count);
			   rightjust(descr);
			   fputs(" (",fp);
			   fputs(descr,fp);
			   fputs(")",fp);

			   free(descr);
			   found = TRUE;
			}
			free(tablename);
			free(attr);
			free_row( vdtrow, vdt );
			if (found) break;
		     }
		  }

		  fputc('\n',fp);
	       }
	    } else {
	       get_table_element(i,row,table,&lptr,&count);
	       fputs(table.header[i].name,fp);
	       fputs(" - ",fp);
	       fputs(table.header[i].description,fp);
	       fputs(": (",fp);
	       for (j=0;j<count;j++) {
		  ltoa((int)lptr[j],num,10);
		  fputs(num,fp);
		  if (j<count-1) fputs(", ",fp);
	       }
	       fputs(")\n",fp);
	    }
	    break;
	 case 'S':
	    if (table.header[i].count==1) {
	       get_table_element(i,row,table,&s,&count);
	       if (s != NULLSHORT) {
		  fputs(table.header[i].name,fp);
		  fputs(" - ",fp);
		  fputs(table.header[i].description,fp);
		  fputs(": ",fp);
		  itoa(s,num,10);
		  fputs(num,fp);

		  strcpy( path, table.path );
		  strcat( path, table.header[i].vdt );
		  if ( (access(path,4)==0) &&
		     (strcmp(table.header[i].vdt,"") != 0) ) {

		     if (strcmp(vdtpath,path) != 0) {
			if (strcmp(vdtpath,"") != 0) {
			   vpf_close_table(&vdt);
			}
			vdt = vpf_open_table( path, disk, "rb", NULL );
		     }
		     strcpy( vdtpath, path );

		     for (j=1;j<=vdt.nrows;j++) {
			vdtrow = read_row( j, vdt );
			tablename = (char *)get_table_element( TABLE_,
					      vdtrow, vdt, NULL, &count );
			rightjust(tablename);
			strupr2(tablename);
			attr = (char *)get_table_element( ATTR_, vdtrow, vdt,
							  NULL, &count );
			rightjust(attr);
			get_table_element( VAL_, vdtrow, vdt,
					   &sval, &count );

			found = FALSE;
			if ( (strstr(table.name,tablename)) &&
			   (ossim_strcasecmp(attr,table.header[i].name)==0) &&
			   (sval==s) ) {
			   descr = (char *)get_table_element(DESCR_,vdtrow,
							 vdt, NULL, &count);
			   rightjust(descr);
			   fputs(" (",fp);
			   fputs(descr,fp);
			   fputs(")",fp);

			   free(descr);
			   found = TRUE;
			}
			free(tablename);
			free(attr);
			free_row( vdtrow, vdt );
			if (found) break;
		     }
		  }

		  fputc('\n',fp);
	       }
	    } else {
	       get_table_element(i,row,table,&sptr,&count);
	       fputs(table.header[i].name,fp);
	       fputs(" - ",fp);
	       fputs(table.header[i].description,fp);
	       fputs(": (",fp);
	       for (j=0;j<count;j++) {
		  itoa(sptr[j],num,10);
		  fputs(num,fp);
		  if (j<count-1) fputs(", ",fp);
	       }
	       fputs(")\n",fp);
	    }
	    break;
	 case 'F':
	    if (table.header[i].count==1) {
	       get_table_element(i,row,table,&f,&count);
	       if (!is_vpf_null_float(f)) {
		  fputs(table.header[i].name,fp);
		  fputs(" - ",fp);
		  fputs(table.header[i].description,fp);
		  fputs(": ",fp);
#if !defined(__APPLE__) && !defined(__FreeBSD__)
		  gcvt(f,6,num);
#endif
		  fputs(num,fp);
		  fputc('\n',fp);
	       }
	    } else {
	       get_table_element(i,row,table,&fptr,&count);
	       fputs(table.header[i].name,fp);
	       fputs(" - ",fp);
	       fputs(table.header[i].description,fp);
	       fputs(": (",fp);
	       for (j=0;j<count;j++) {
		  if (is_vpf_null_float(fptr[j])) {
		     fputs("(null)",fp);
		  } else {
#if !defined(__APPLE__) && !defined(__FreeBSD__)
		     gcvt(fptr[j],6,num);
#endif
		     fputs(num,fp);
		  }
		  if (j<count-1) fputs(", ",fp);
	       }
	       fputs(")\n",fp);
	    }
	    break;
	 case 'D':
	    if (table.header[i].count==1) {
	       get_table_element(i,row,table,date,&count);
	       fputs(table.header[i].name,fp);
	       fputs(" - ",fp);
	       fputs(table.header[i].description,fp);
	       fputs(": ",fp);
	       format_date(date,fmtdate);
	       fputs(fmtdate,fp);
	       fputc('\n',fp);
	    }
	    break;
      }
   }

   if (strcmp(vdtpath,"") != 0)
      vpf_close_table( &vdt );

   free(num);
}
コード例 #13
0
/**************************************************************************
 *
 *N  fcs_relate_list
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Read the feature class schema table and create the list of
 *    tables to chain through.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    fcname       <input> == (char *) feature class name.
 *    start_table  <input> == (char *) table to start from.
 *    end_table    <input> == (char *) table to end with.
 *    fcs          <input> == (vpf_table_type) feature class schema table.
 *    fcs_relate_list <output> == (linked_list_type) list of tables to
 *                                chain through.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
linked_list_type fcs_relate_list( char *fcname, char *start_table,
				  char *end_table, vpf_table_type fcs )
{
   linked_list_type rlist;
   vpf_relate_struct rstruct;
   set_type fcset, set1, set2;
   char tablename[255], *buf, expr[255];
   row_type row;
   long int rownum,n;
   int TABLE1_, KEY1_, TABLE2_, KEY2_;

   rlist = ll_init();

   sprintf(expr,"FEATURE_CLASS = %s",fcname);

   fcset = query_table(expr,fcs);

   if (set_empty(fcset)) {
      set_nuke(&fcset);
      return rlist;
   }

   TABLE1_ = table_pos("TABLE1",fcs);
   KEY1_ = table_pos("FOREIGN_KEY",fcs);
   if (KEY1_ < 0) KEY1_ = table_pos("TABLE1_KEY",fcs);
   TABLE2_ = table_pos("TABLE2",fcs);
   KEY2_ = table_pos("PRIMARY_KEY",fcs);
   if (KEY2_ < 0) KEY2_ = table_pos("TABLE2_KEY",fcs);

   strcpy( tablename, start_table );
   while (1) {
      sprintf(expr,"TABLE1 = %s",tablename);

      set1 = query_table(expr,fcs);
      set2 = set_intersection(set1,fcset);
      set_nuke(&set1);
      if (set_empty(set2)) {
	 set_nuke(&fcset);
	 set_nuke(&set2);
	 return rlist;
      }
      rownum = set_min(set2);

      set_nuke(&set2);

      row = get_row(rownum,fcs);

      buf = (char *)get_table_element(TABLE1_,row,fcs,NULL,&n);
      strcpy(rstruct.table1,buf);
      rightjust(rstruct.table1);
      free(buf);

      buf = (char *)get_table_element(KEY1_,row,fcs,NULL,&n);
      strcpy(rstruct.key1,buf);
      rightjust(rstruct.key1);
      free(buf);

      buf = (char *)get_table_element(TABLE2_,row,fcs,NULL,&n);
      strcpy(rstruct.table2,buf);
      rightjust(rstruct.table2);
      free(buf);

      buf = (char *)get_table_element(KEY2_,row,fcs,NULL,&n);
      strcpy(rstruct.key2,buf);
      rightjust(rstruct.key2);
      free(buf);

      rstruct.degree = R_ONE;  /* Default */

      free_row( row, fcs );

      if (table_in_list(rstruct.table1, rlist)) break;

      ll_insert( &rstruct, sizeof(rstruct), ll_last(rlist) );

      strcpy( tablename, rstruct.table2 );

      if (ossim_strcasecmp(tablename,end_table)==0) break;
   }

   set_nuke(&fcset);

   return rlist;
}
コード例 #14
0
/**************************************************************************
 *
 *N  vpf_dump_table
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Dump the contents of a VPF table into an ASCII file
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    tablename <input> == (char *) VPF table to dump.
 *    outname   <input> == (char *) name of ASCII dump file.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
void vpf_dump_table( char *tablename, char *outname )
{
   vpf_table_type table;
   long int   i,j,k,n;
   int        ival,*iptr;
   long int   lval,*lptr;
   float      fval,*fptr;
   date_type  dval,*dptr;
   id_triplet_type kval, *kptr;
   coordinate_type cval, *cptr;
   char       *buf,  ch, date[40];
   row_type   row;
   FILE       *fp;

   fp = fopen(outname,"w");

   table = vpf_open_table(tablename,disk,"rb",NULL);

   fprintf(fp,"%s\n%s\n\n",tablename,table.description);

   fprintf(fp,"Definition:\n");
   for (i=0;i<table.nfields;i++) {
      if (table.header[i].count < 0)
	 fprintf(fp,"%s (%c,*)  %s\n",
		 table.header[i].name,table.header[i].type,
		 table.header[i].description);
      else
	 fprintf(fp,"%s (%c,%ld)  %s\n",
		 table.header[i].name,table.header[i].type,
		 table.header[i].count,table.header[i].description);
   }

   fprintf(fp,"\nContents:\n");
   for (i=1;i<=table.nrows;i++) {
      row = read_next_row(table);
      for (j=0;j<table.nfields;j++) {
	 fprintf(fp,"%s: ",table.header[j].name);
	 switch (table.header[j].type) {
	    case 'T':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&ch,&n);
		  fprintf(fp,"%c\n",ch);
	       } else {
		  buf = (char *)get_table_element(j,row,table,NULL,&n);
		  n = (long)strlen(table.header[j].name) + 2;
		  for (k=0;(unsigned int)k<strlen(buf);k++) {
		     fprintf(fp,"%c",buf[k]);
		     n++;
		     if (n>80) {
			fprintf(fp,"\n");
			n = 0;
		     }
		  }
		  fprintf(fp,"\n");
		  free(buf);
	       }
	       break;
	    case 'I':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&lval,&n);
		  if (lval != MAXFLOAT)
		     fprintf(fp,"%ld\n",lval);
		  else
		     fprintf(fp,"(null)\n");
	       } else {
		  lptr = (long int*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++) {
		     if (lptr[k] != MAXFLOAT)
			fprintf(fp,"%ld ",lptr[k]);
		     else
			fprintf(fp,"(null) ");
		  }
		  fprintf(fp,"\n");
		  free(lptr);
	       }
	       break;
	    case 'S':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&ival,&n);
		  if (ival != MAXINT)
		     fprintf(fp,"%d\n",ival);
		  else
		     fprintf(fp,"(null)\n");
	       } else {
		  iptr = (int*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++) {
		     if (iptr[k] != MAXINT)
			fprintf(fp,"%d ",iptr[k]);
		     else
			fprintf(fp,"(null) ");
		  }
		  fprintf(fp,"\n");
		  free(iptr);
	       }
	       break;
	    case 'F':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&fval,&n);
		  if (fval != MAXFLOAT)
		     fprintf(fp,"%f\n",fval);
		  else
		     fprintf(fp,"(null)\n");
	       } else {
		  fptr = (float*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++) {
		     if (fptr[k] != MAXFLOAT)
			fprintf(fp,"%f ",fptr[k]);
		     else
			fprintf(fp,"(null) ");
		  }
		  fprintf(fp,"\n");
		  free(fptr);
	       }
	       break;
	    case 'C':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&cval,&n);
		  fprintf(fp,"(%f,%f)\n",cval.x,cval.y);
	       } else {
		  cptr = (coordinate_type*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++)
		     fprintf(fp,"(%f,%f) ",cptr[k].x,cptr[k].y);
		  fprintf(fp,"\n");
		  free(cptr);
	       }
	       break;
	    case 'K':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&kval,&n);
		  fprintf(fp,"(%ld,%ld,%ld)\n",
			  kval.id,kval.tile,kval.exid);
	       } else {
		  kptr = (id_triplet_type*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++)
		     fprintf(fp,"(%ld,%ld,%ld)  ",
			     kptr[k].id,kptr[k].tile,kptr[k].exid);
		  fprintf(fp,"\n");
		  free(kptr);
	       }
	       break;
	    case 'D':   /* Date */
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&dval,&n);
		  format_date(dval,date);
		  fprintf(fp,"%s\n",date);
	       } else {
		  dptr = (date_type*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++) {
		     format_date((char*)(&dptr[k]),date);
		     fprintf(fp,"%s ",date);
		  }
		  fprintf(fp,"\n");
		  free(dptr);
	       }
	       break;
	 }
      }
      fprintf(fp,"\n");
      free_row( row, table );
   }

   fclose(fp);
   vpf_close_table( &table );
}
コード例 #15
0
ファイル: vpfselec.c プロジェクト: vapd-radi/rspf_v2.0
/*************************************************************************
 *
 *N  draw_selected_features
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    This function draws the selected features from a specified feature
 *    class based upon a query (either an expression or the pre-compiled
 *    results of an expression).
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     view     <inout>==(view_type *) view structure.
 *     themenum <input>==(int) theme number.
 *     library  <input>==(library_type *) VPF library structure.
 *     mapenv   <input>==(map_environment_type *) map environment structure.
 *     return  <output>==(int) completion status:
 *                                1 if completed successfully,
 *                                0 if an error occurred.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   August 1991                        DOS Turbo C
 *E
 *************************************************************************/
int draw_selected_features( view_type *view,
			    int themenum,
			    library_type *library,
			    map_environment_type *mapenv )
{
   int status, fcnum, finished, cov, tilecover, TILEPATH_, prim;
   int outline, color1, color2, color3, color4;
   vpf_table_type rngtable,edgtable,fbrtable, tile_table;
   row_type row;
   char *ptable[] = {"","edg","fac","txt","end","cnd"};
   register rspf_int32 i, j, p, pclass, tile;
   int display_order[] = {FACE,EDGE,ENTITY_NODE,CONNECTED_NODE,TEXT};
   register rspf_int32 starttile, endtile, startprim, endprim;
   rspf_int32 count;
   char path[255], covpath[255], tiledir[255], *buf, str[255];
   char *drive, rngpath[255],edgpath[255],edxpath[255],fbrpath[255];
   boolean rng_rdisk,edg_rdisk,fbr_rdisk;
   set_type primitives, feature_rows;
   fcrel_type fcrel;
   window_type info;
   struct viewporttype vp;

   getviewsettings(&vp);

   fcnum = view->theme[themenum].fcnum;

   sprintf(path,"%stileref\\tileref.aft",library->path);
   if (access(path,0) != 0) {
      tilecover = FALSE;
   } else {
      tile_table = vpf_open_table(path,disk,"rb",NULL);
      TILEPATH_ = table_pos("TILE_NAME",tile_table);
      tilecover = TRUE;
   }

   feature_rows = get_selected_features( view, themenum, *library );

   for (p=0;p<5;p++) {
      pclass = display_order[p];

      if ((pclass != library->fc[fcnum].primclass) &&
	  (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue;

      if ((library->fc[fcnum].primclass == COMPLEX_FEATURE) &&
	  (!library->fc[fcnum].cprim[pclass])) continue;

      /* Set up the feature class table relate chain.        */
      /* The feature table is fcrel.table[0].                */
      /* The primitive table is the last table in the chain: */
      /*    fcrel.table[ fcrel.nchain-1 ].                   */

      j = 0;
      for (i=0;i<strlen(library->fc[fcnum].table);i++)
	 if (library->fc[fcnum].table[i] == '\\') j = i+1;
      strcpy( str, &(library->fc[fcnum].table[j]));
      fcrel = select_feature_class_relate(fcnum, library, str,
					  ptable[pclass]);
      prim = fcrel.nchain-1;

      /*** 'Tile' number 1 is the universe polygon for
	   the tileref cover ***/
      starttile = set_min(library->tile_set);
      if (starttile < 2) starttile = 2;
      endtile = set_max(library->tile_set);
      if (endtile < 2) endtile = 2;

      for (tile = starttile; tile <= endtile; tile++ ) {

	 if (!set_member(tile,library->tile_set)) continue;

	 if (tilecover) {
	    row = get_row(tile,tile_table);
	    buf = (char *)get_table_element(TILEPATH_,row,tile_table,
					     NULL,&count);
	    free_row(row,tile_table);
	    strcpy(tiledir,buf);
	    rightjust(tiledir);
	    strcat(tiledir,"\\");
	    free(buf);
	 } else {
	    strcpy(tiledir,"");
	 }

	 cov = library->fc[fcnum].coverage;
	 strcpy( covpath, library->cover[cov].path );

	 finished = TRUE;

	 sprintf(path,"%s%s%s",covpath,tiledir,ptable[pclass]);

	 if (access(path,0) != 0) continue;
	 fcrel.table[prim] = vpf_open_table(path,disk,"rb",NULL);

	 info = info_window("Searching...");

	 primitives = get_selected_tile_primitives( library,
						    fcnum, fcrel,
						    feature_rows,
						    mapenv,
						    tile, tiledir,
						    &status );
	 delete_window(&info);
	 setviewport(vp.left,vp.top,vp.right,vp.bottom,vp.clip);

	 /* Reset plate-carree parameters (changed in  */
	 /* get_selected_tile_primitives() )           */
	 if (mapenv->projection == PLATE_CARREE)
	    set_plate_carree_parameters( central_meridian(
					 mapenv->mapextent.x1,
					 mapenv->mapextent.x2),
					 0.0, 1.0 );

	 if (primitives.size < 1) {
	    vpf_close_table(&fcrel.table[prim]);
	    continue;
	 }

	 if (!status) {
	    set_nuke(&primitives);
	    vpf_close_table(&fcrel.table[prim]);
	    break;
	 }

	 if (pclass == FACE) {
	    /* Must also open RNG, EDG, and FBR for drawing faces. */
	    /* If a RAM disk is specified, copy these to it and open */
	    /* them there. */
	    rng_rdisk = FALSE;
	    edg_rdisk = FALSE;
	    fbr_rdisk = FALSE;
	    drive = getenv("TMP");
	    buf = (char *)vpfmalloc(255);

	    sprintf(path,"%s%srng",covpath,tiledir);
	    strcpy(rngpath,path);
	    if (drive && filesize(path) < available_space(drive)) {
	       sprintf(rngpath,"%s\\RNG",drive);
	       sprintf(buf,"COPY %s %s > NUL",path,rngpath);
	       system(buf);
	       rng_rdisk = TRUE;
	    }
	    rngtable = vpf_open_table(rngpath,disk,"rb",NULL);

	    sprintf(path,"%s%sedg",covpath,tiledir);
	    strcpy(edgpath,path);
            sprintf(edxpath,"%s%sedx",covpath,tiledir);
	    if (drive &&
	       (filesize(path)+filesize(edxpath))<available_space(drive)) {
	       sprintf(edgpath,"%s\\EDG",drive);
	       sprintf(buf,"COPY %s %s > NUL",path,edgpath);
	       system(buf);
	       sprintf(edxpath,"%s\\EDX",drive);
	       sprintf(buf,"COPY %s%sedx %s > NUL",covpath,tiledir,edxpath);
	       system(buf);
	       edg_rdisk = TRUE;
	    }
	    edgtable = vpf_open_table(edgpath,disk,"rb",NULL);

	    sprintf(path,"%s%sfbr",covpath,tiledir);
	    strcpy(fbrpath,path);
	    if (drive && filesize(path) < available_space(drive)) {
	       sprintf(fbrpath,"%s\\FBR",drive);
	       sprintf(buf,"COPY %s %s > NUL",path,fbrpath);
	       system(buf);
	       fbr_rdisk = TRUE;
	    }
	    fbrtable = vpf_open_table(fbrpath,disk,"rb",NULL);

	    free(buf);
	 }

	 finished = 1;

	 startprim = set_min(primitives);
	 endprim = set_max(primitives);

	 /* It turns out to be MUCH faster off of a CD-ROM to */
	 /* read each row and discard unwanted ones than to   */
	 /* forward seek past them.  It's about the same off  */
	 /* of a hard disk.				      */

	 fseek(fcrel.table[prim].fp,
	       index_pos(startprim,fcrel.table[prim]),
	       SEEK_SET);

	 for (i=startprim;i<=endprim;i++) {

	    row = read_next_row(fcrel.table[prim]);

	    if (set_member( i, primitives )) {
	       /* Draw the primitive */
	       switch (pclass) {
		  case EDGE:
		     finished = draw_edge_row(row,fcrel.table[prim]);
		     break;
		  case ENTITY_NODE:
		  case CONNECTED_NODE:
		     finished = draw_point_row(row,fcrel.table[prim]);
		     break;
		  case FACE:
		     gpgetlinecolor( &outline );
		     gpgetpattern( &color1, &color2, &color3, &color4 );
		     hidemousecursor();
		     draw_face_row( row,fcrel.table[prim],
				    rngtable, edgtable, fbrtable,
				    outline,
				    color1, color2, color3, color4 );
		     showmousecursor();
		     finished = 1;
		     if (kbhit()) {
			if (getch()==27) finished = 0;
		     }
		     break;
		  case TEXT:
		     finished = draw_text_row(row,fcrel.table[prim]);
		     break;
	       }
	    }

	    free_row(row,fcrel.table[prim]);

	    if (!finished) {
	       status = 0;
	       break;
	    }
	 }

	 if (pclass == FACE) {
	    vpf_close_table(&rngtable);
	    if (rng_rdisk) remove(rngpath);
	    vpf_close_table(&edgtable);
	    if (edg_rdisk) {
	       remove(edgpath);
	       remove(edxpath);
	    }
	    vpf_close_table(&fbrtable);
	    if (fbr_rdisk) remove(fbrpath);
	 }

	 vpf_close_table(&fcrel.table[prim]);

	 set_nuke(&primitives);

	 if (!finished) {
	    status = 0;
	    break;
	 }

      }

      if (!finished) {
	 status = 0;
	 deselect_feature_class_relate( &fcrel );
	 break;
      }

      status = 1;

      if (kbhit()) {
	 if (getch()==27) {
	    status = 0;
	    deselect_feature_class_relate( &fcrel );
	    break;
	 }
      }

      deselect_feature_class_relate(&fcrel);
   }

   if (tilecover) {
      vpf_close_table(&tile_table);
   }

   set_nuke(&feature_rows);

   return status;
}
コード例 #16
0
ファイル: ossimVpfTable.cpp プロジェクト: LucHermitte/ossim
void ossimVpfTable::print(std::ostream& out)const
{
   if(theTableInformation &&
      (theTableInformation->status!=CLOSED))
   {
      // make sure we are at the beginning of the table.
      this->reset();


      // the rest of this code is from the vpfutil.  The vpfutil
      // was grabbed from the vhcl map server software.
      vpf_table_type& table = *theTableInformation;

      ossim_int32       i,j,k,n;
      ossim_int16  ival=0,*iptr=NULL;
      ossim_int32       lval=0,*lptr=NULL;
      ossim_float32      fval=0,*fptr=NULL;
      date_type  dval,*dptr=NULL;
      id_triplet_type kval={0,0,0}, *kptr=NULL;
      coordinate_type cval={0,0}, *cptr=NULL;
      char       *buf,  ch, date[40];
      row_type   row;


    out << "table name:        " << theTableName << std::endl
      << "desciption:        " << table.description << std::endl
      << std::endl;

    out << "Definition:" << std::endl;
      for (i=0;i<table.nfields;i++) {
         if (table.header[i].count < 0)
         {

            out << table.header[i].name << " ("
                << table.header[i].type << ",*)  "
        << table.header[i].description << std::endl;
         }
         else
         {
            out << table.header[i].name << " ("
                << table.header[i].type << ","
                << table.header[i].count << ")  "
        << table.header[i].description << std::endl;
         }
      }

    out << "\nContents:" << std::endl;
      for (i=1;i<=table.nrows;i++)
      {
         row = read_next_row(table);
         for (j=0;j<table.nfields;j++)
         {
            out << table.header[j].name << ": ";
            switch (table.header[j].type) {
      case 'T':
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&ch,&n);

      out << ch << std::endl;
         }
               else
               {
      buf = (char *)get_table_element(j,row,table,NULL,&n);
      n = (long)strlen(table.header[j].name) + 2;
      for (k=0;k<(long)strlen(buf);k++)
                  {
                     out << buf[k];
         n++;
         if (n>80)
                     {
             out << std::endl;
      n = 0;
         }
      }
          out << std::endl;
      free(buf);
         }
         break;
      case 'I': // long
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&lval,&n);
      if (!is_vpf_null_float(lval))
                  {
            out << lval << std::endl;
                  }
      else
                  {
            out << "null" << std::endl;
                  }
         }
               else
               {
      lptr = (ossim_int32*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
         if (!is_vpf_null_float(lptr[k]))
                     {
                        out << lptr[k];
                     }
         else
                     {
                        out << "null";
                     }
      }
          out << std::endl;
      free(lptr);
         }
         break;
            case 'R': // for double
            {
               double *dptr=NULL;
               double value = 0;
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&value,&n);
                  if(!is_vpf_null_double(value))
                  {
            out << "null" << std::endl;
                  }
                  else
                  {
            out << value << std::endl;
                  }
               }
               else
               {
      dptr = (double*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
         if (!is_vpf_null_double(dptr[k]))
                     {
                        out << dptr[k];
                     }
         else
                     {
                        out << "null ";
                     }
      }
          out << std::endl;
      free(dptr);
               }
            }
      case 'S': // integer
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&ival,&n);
      if (ival != (short int)INT_MAX)
                  {
            out << ival << std::endl;
                  }
      else
                  {
            out << "null" << std::endl;
                  }
         }
               else
               {
      iptr = (short int*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
         if (iptr[k] != (short int)INT_MAX)
                     {
                        out << iptr[k];
                     }
         else
                     {
                        out << "null ";
                     }
      }
          out << std::endl;
      free(iptr);
         }
         break;
      case 'F': // float type
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&fval,&n);
      if (!is_vpf_null_float(fval))
                  {
            out << fval << std::endl;
                  }
      else
                  {
            out << "null" << std::endl;
                  }
         }
               else
               {
      fptr = (float*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
         if (!is_vpf_null_float(fptr[k]))
                     {
                        out << fptr[k] << " ";
                     }
         else
                     {
                        out << "null ";
                     }
      }
          out << std::endl;
      free(fptr);
         }
         break;
            case 'Y':
            {
               double_tri_coordinate_type dtctValue, *dtctPtr;
         if (table.header[j].count==1)
               {
                  get_table_element(j,row,table,&dtctValue,&n);
                  out << "(";
                  if(is_vpf_null_double(dtctValue.x))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << dtctValue.x << ", ";
                  }
                  if(is_vpf_null_double(dtctValue.y))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << dtctValue.y << ", ";
                  }
                  if(is_vpf_null_double(dtctValue.z))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << dtctValue.z << ", ";
                  }
               }
               else
               {
      dtctPtr = (double_tri_coordinate_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
                     out << "(";
                     if(is_vpf_null_double(dtctPtr[k].x))
                     {
                        out << "null, ";
                     }
                     else
                     {
                        out << dtctPtr[k].x  << ", ";
                     }
                     if(is_vpf_null_double(dtctPtr[k].y))
                     {
                        out << "null, ";
                     }
                     else
                     {
                        out << dtctPtr[k].y  << ", ";
                     }
                     if(is_vpf_null_double(dtctPtr[k].z))
                     {
                        out << "null, ";
                     }
                     else
                     {
                        out << dtctPtr[k].z  << ", ";
                     }
                  }
                  free(dtctPtr);
               }
               break;
            }
            case 'Z': // tri coordinate types x, y, z
            {
               tri_coordinate_type tcval={0,0,0}, *tcptr=NULL;
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&tcval,&n);
                  out << "(";
                  if(is_vpf_null_float(tcval.x))
                  {
                     out << "null" << ",";
                  }
                  else
                  {
                     out << tcval.x << ", ";
                  }
                  if(is_vpf_null_float(tcval.y))
                  {
                     out << "null" << ", ";
                  }
                  else
                  {
                     out << tcval.y << ", ";
                  }
                  if(is_vpf_null_float(tcval.z))
                  {
            out << "null)" << std::endl;
                  }
                  else
                  {
            out << tcval.z << ")" << std::endl;
                  }
         }
               else
               {
      tcptr = (tri_coordinate_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
                     out << "(";
                     if(is_vpf_null_float(tcptr[k].x))
                     {
                        out << "null, ";
                     }
                     else
                     {
                        out << tcptr[k].x << ", ";
                     }
                     if(is_vpf_null_float(tcptr[k].y))
                     {
                        out << "null, ";
                     }
                     else
                     {
                        out << tcptr[k].y << ", ";
                     }
                     if(is_vpf_null_float(tcptr[k].z))
                     {
                        out << "null)";
                     }
                     else
                     {
                        out << tcptr[k].z << ")";
                     }
                  }
          out << std::endl;
      free(tcptr);
         }
         break;
            }
      case 'C': // coordinate type  x, y
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&cval,&n);
                  out << "(";
                  if(is_vpf_null_float(cval.x))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << cval.x << ", ";
                  }
                  if(is_vpf_null_float(cval.y))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << cval.y << ")";
                  }
         }
               else
               {
      cptr = (coordinate_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {

                     out << "(" << cptr[k].x << "," << cptr[k].y << ") ";
                  }
          out << std::endl;
      free(cptr);
         }
         break;
            case 'B': // double coordinate type
            {
               double_coordinate_type dct, *dctPtr;

         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&dct,&n);

                  out << "(";
                  if(is_vpf_null_double(dct.x))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << dct.x << ", ";
                  }
                  if(is_vpf_null_double(dct.y))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << dct.y << ")";
                  }
         }
               else
               {
      dctPtr = (double_coordinate_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
                     out << "(";
                     if(is_vpf_null_double(dctPtr[k].x))
                     {
                        out << "null,";
                     }
                     else
                     {
                        out << dctPtr[k].x << ", ";
                     }
                     if(is_vpf_null_double(dctPtr[k].y))
                     {
                        out << "null,";
                     }
                     else
                     {
                        out << dctPtr[k].y << ", ";
                     }
                  }
          out << std::endl;
      free(dctPtr);
         }

            }
      case 'K': //id triplet
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&kval,&n);
                  out <<  "(" << kval.id
                      << ", " << kval.tile
                      << ", " << kval.exid
            << ")" << std::endl;
         }
               else
               {
      kptr = (id_triplet_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
                     out <<  "(" << kptr[k].id
                         << ", " << kptr[k].tile
                         << ", " << kptr[k].exid
             << ")  " << std::endl;

                  }
          out << std::endl;
      free(kptr);
         }
         break;
      case 'D':   /* Date */
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&dval,&n);
      format_date(dval,date);
      out << date << std::endl;
         }
               else
               {
      dptr = (date_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
         format_date((char*)(&dptr[k]),date);
                     out << dptr[k] << " ";
      }
          out << std::endl;
      free(dptr);
         }
         break;
            }
         }
     out << std::endl;
         free_row( row, table );
      }
   }
}
コード例 #17
0
bool ossimVpfBoundingRecordTable::openTable(const ossimFilename& tableName)
{
   bool result = false;
   theExtent = ossimVpfExtent(0,0,0,0);
   bool firstOneSetFlag = false;
   
   if(ossimVpfTable::openTable(tableName))
   {
      ossim_int32 xminIdx = getColumnPosition("XMIN");
      ossim_int32 yminIdx = getColumnPosition("YMIN");
      ossim_int32 xmaxIdx = getColumnPosition("XMAX");
      ossim_int32 ymaxIdx = getColumnPosition("YMAX");
      
      if((xminIdx < 0)||
         (yminIdx < 0)||
         (xmaxIdx < 0)||
         (ymaxIdx < 0))
      {
         closeTable();
      }
      else
      {
         if(getNumberOfRows() > 0)
         {
            result = true;
            reset();
            ossim_int32 n = 1;
            
            ossim_float32 xmin;
            ossim_float32 ymin;
            ossim_float32 xmax;
            ossim_float32 ymax;
            
            row_type row;
            for(int rowIdx = 1; rowIdx < getNumberOfRows(); ++rowIdx)
            {
               if(rowIdx == 1)
               {
                  row = read_row(rowIdx,
                                 *theTableInformation);
               }
               else
               {
                  row = read_next_row(*theTableInformation);
               }
               get_table_element(xminIdx,
                                 row,
                                 *theTableInformation,
                                 &xmin,
                                 &n);
               get_table_element(yminIdx,
                                 row,
                                 *theTableInformation,
                                 &ymin,
                                 &n);
               get_table_element(xmaxIdx,
                                 row,
                                 *theTableInformation,
                                 &xmax,
                                 &n);
               get_table_element(ymaxIdx,
                                 row,
                                 *theTableInformation,
                                 &ymax,
                                 &n);
               if(!is_vpf_null_float(xmin)&&
                  !is_vpf_null_float(ymin)&&
                  !is_vpf_null_float(xmax)&&
                  !is_vpf_null_float(ymax))
               {
                  if(!firstOneSetFlag)
                  {
                     theExtent = ossimVpfExtent(xmin,
                                                ymin,
                                                xmax,
                                                ymax);
                     firstOneSetFlag = true;
                  }
                  else
                  {
                     theExtent = theExtent + ossimVpfExtent(xmin,
                                                            ymin,
                                                            xmax,
                                                            ymax);
                  }                  
               }
               free_row(row, *theTableInformation);
            }
         }
      }
   }
   return result;
}
コード例 #18
0
/**************************************************************************
 *
 *N  fc_row_number
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Given the starting row of a feature class relationship, return the
 *    row number of the table at the end of the feature class relate
 *    chain.
 *    If your relate goes from the feature to the primitive, this will
 *    return the primitive id for the given feature row.
 *    If your relate goes from the primitive to the feature, this will
 *    return the feature id of the given primitive row.
 *
 *    Currently only supports relates on 'I' or 'K' fields.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
long int fc_row_number( row_type row, fcrel_type fcrel, long int tile )
{
   row_type relrow;
   long int count;
   long int i, rownum, keyval;
   id_triplet_type triplet_keyval;
   int KEY1_, KEY_;
   position_type p;
   vpf_relate_struct rcell;

   p = ll_first(fcrel.relate_list);
   ll_element(p,&rcell);
   KEY1_ = table_pos(rcell.key1,fcrel.table[0]);

   get_table_element(0,row,fcrel.table[0],&rownum,&count);

   if (KEY1_ == 0) {     /* "ID" */
      keyval = rownum;
   } else {
      switch (fcrel.table[0].header[KEY1_].type) {
	 case 'I':
	    get_table_element(KEY1_,row,fcrel.table[0],&keyval,&count);
	    break;
	 case 'K':
	    get_table_element(KEY1_,row,fcrel.table[0],&triplet_keyval,
			      &count);
	    keyval = triplet_keyval.exid;
	    if (tile != triplet_keyval.tile) {
	       return -2;
	    }
	    break;
	 default:
	    keyval = 0;
	    break;
      }
   }

   p = ll_first(fcrel.relate_list);
   for (i=1;i<(fcrel.nchain-1);i++) {
      /* Relate through Join table(s) */
      rownum = related_row(&keyval,fcrel.table[i],rcell.key2,0);
      relrow = get_row(rownum,fcrel.table[i]);

      p = ll_next(p);
      ll_element(p,&rcell);
      KEY_ = table_pos(rcell.key1,fcrel.table[i]);

      if (KEY_ == 0) {     /* "ID" */
	 keyval = rownum;
      } else {
	 switch (fcrel.table[i].header[KEY_].type) {
	 case 'I':
	    get_table_element(KEY_,relrow,fcrel.table[i],&keyval,&count);
	    break;
	 case 'K':
	    get_table_element(KEY_,relrow,fcrel.table[i],&triplet_keyval,
			      &count);
	    keyval = triplet_keyval.exid;
	    if (tile != triplet_keyval.tile) {
	       return -2;
	    }
	    break;
	 default:
	    keyval = 0;
	    break;
	 }
      }

      free_row(relrow,fcrel.table[i]);
   }

   if (ossim_strcasecmp(rcell.key2,"ID")==0)
      rownum = keyval;
   else
      rownum = related_row(&keyval,fcrel.table[i],rcell.key2,0);

   return rownum;
}
コード例 #19
0
ファイル: vpfselec.c プロジェクト: vapd-radi/rspf_v2.0
/*************************************************************************
 *
 *N  get_selected_primitives
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    This function determines all of the selected primitive rows from
 *    the selected features.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     view     <input> == (view_type *) view structure.
 *     themenum <input> == (int) theme number.
 *     library  <input> == (library_type *) VPF library structure.
 *     mapenv   <input> == (map_environment_type *) map environment.
 *     status  <output> == (int *) status of the function:
 *                         1 if completed, 0 if user escape.
 *     get_selected_primitives <output> == (set_type *) array of sets, each position
 *                         representing the set of primitives for the
 *                         corresponding tile in the tileref.aft table.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   May 1991                           DOS Turbo C
 *E
 *************************************************************************/
set_type *get_selected_primitives( view_type *view,
				   int themenum,
				   library_type *library,
				   map_environment_type *mapenv,
				   int *status )
{
   int fcnum, finished, found, cov, tilecover, TILEPATH_, degree;
   int feature, prim;
   vpf_table_type tile_table;
   row_type row;
   char *ptable[] = {"","edg","fac","txt","end","cnd"};
   char *spxname[] = {"","esi","fsi","tsi","nsi","csi"};
   char *brname[] = {"","ebr","fbr","tbr","nbr","cbr"};
   set_type feature_rows, primitive_rows, tile_features;
   set_type *primitives;
   rspf_int32 prim_rownum, count, tile;
   register rspf_int32 i,j, pclass, start,end;
   char path[255], covpath[255], tiledir[255], *buf, str[255];
   fcrel_type fcrel;
   linked_list_type primlist;
   position_type p;
   vpf_relate_struct rcell;
   ThematicIndex idx;

   primitives = (set_type *)vpfmalloc((library->ntiles+1)*sizeof(set_type));
   for (i=0;i<=library->ntiles;i++) {
      primitives[i].size = 0;
      primitives[i].buf = NULL;
   }

   fcnum = view->theme[themenum].fcnum;

   feature_rows = get_selected_features( view, themenum, *library );

   /* Open the tile reference table, if present */
   sprintf(path,"%stileref\\tileref.aft",library->path);
   if (access(path,0) != 0) {
      tilecover = FALSE;
   } else {
      tile_table = vpf_open_table(path,disk,"rb",NULL);
      TILEPATH_ = table_pos("TILE_NAME",tile_table);
      tilecover = TRUE;
   }

   for (pclass=EDGE;pclass<=CONNECTED_NODE;pclass++) {

      if ((pclass != library->fc[fcnum].primclass) &&
	  (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue;

      /* Set up the feature class table relate chain.        */
      /* The feature table is fcrel.table[0].                */
      /* The primitive table is the last table in the chain: */
      /*    fcrel.table[ fcrel.nchain-1 ].                   */

      j = 0;
      for (i=0;i<strlen(library->fc[fcnum].table);i++)
	 if (library->fc[fcnum].table[i] == '\\') j = i+1;
      strcpy( str, &(library->fc[fcnum].table[j]));
      fcrel = select_feature_class_relate(fcnum, library, str,
					  ptable[pclass]);
      feature = 0;
      prim = fcrel.nchain-1;

      p = ll_previous(ll_last(fcrel.relate_list),fcrel.relate_list);
      ll_element(p,&rcell);
      degree = rcell.degree;

      /*** 'Tile' number 1 is the universe polygon for the tileref cover ***/
      for (tile = 2; tile <= library->ntiles; tile++ ) {

	 if (!set_member(tile,library->tile_set)) continue;

	 if (tilecover) {
	    row = get_row(tile,tile_table);
	    buf = (char *)get_table_element(TILEPATH_,row,tile_table,
					     NULL,&count);
	    free_row(row,tile_table);
	    strcpy(tiledir,buf);
	    rightjust(tiledir);
	    strcat(tiledir,"\\");
	    free(buf);
	 } else {
	    strcpy(tiledir,"");
	 }

	 cov = library->fc[fcnum].coverage;
	 strcpy( covpath, library->cover[cov].path );

	 finished = 1;
	 found = 0;

	 /* Open primitive table in tile */
	 sprintf(path,"%s%s%s",covpath,tiledir,ptable[pclass]);
	 if (access(path,0) != 0) continue;
	 found = 1;
	 fcrel.table[prim] = vpf_open_table(path,disk,"rb",NULL);

	 if (primitives[tile].size > 0) {
	    printf("Oops!  size = %ld\n",primitives[tile].size);
	    exit(1);
	 }
	 primitives[tile] = set_init(fcrel.table[prim].nrows+1);

	 /* Get the set of primitive rows within the map extent */

	 /* Look for spatial index file */
	 primitive_rows.size = 0;
	 if (mapenv->projection == PLATE_CARREE &&
	     mapenv->mapextent.x1 < mapenv->mapextent.x2) {
	    sprintf(path,"%s%s%s",covpath,tiledir,spxname[pclass]);
	    if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) {

	       primitive_rows = spatial_index_search(path,
			  mapenv->mapextent.x1,mapenv->mapextent.y1,
			  mapenv->mapextent.x2,mapenv->mapextent.y2);

	    } else {
	       /* Next best thing - bounding rectangle table */
	       sprintf(path,"%s%s%s",covpath,tiledir,brname[pclass]);
	       if (access(path,0)==0) {
		  primitive_rows = bounding_select(path,mapenv->mapextent,
						   library->dec_degrees);
	       }
	    }
	 } /* projection check */

	 if (primitive_rows.size == 0) {
	    /* Search through all the primitives */
	    primitive_rows=set_init(fcrel.table[prim].nrows+1);
	    set_on(primitive_rows);
	 }

	 tile_thematic_index_name(fcrel.table[feature], path);
	 if ( (strcmp(path,"") != 0) && (access(path,4)==0) ) {
	    /* Tile thematic index for feature table present, */
	    tile_features = read_thematic_index( path, (char *)&tile );
	 } else {
	    tile_features = set_init(fcrel.table[feature].nrows+1);
	    set_on(tile_features);
	 }

	 idx.fp = NULL;
	 i = table_pos(rcell.key2,fcrel.table[prim]);
	 if (i >= 0) {
	    if (fcrel.table[prim].header[i].tdx) {
	       sprintf(path,"%s%s",fcrel.table[prim].path,
				fcrel.table[prim].header[i].tdx);
	       if (access(path,0)==0)
		  idx = open_thematic_index(path);
	    }
	    if (fcrel.table[prim].header[i].keytype == 'U') degree = R_ONE;
	    if (fcrel.table[prim].header[i].keytype == 'N') degree = R_MANY;
	    if (fcrel.table[prim].header[i].keytype == 'P') degree = R_ONE;
	 }

	 finished = 1;

	 start = set_min(tile_features);
	 end = set_max(tile_features);

	 fseek(fcrel.table[feature].fp,
	       index_pos(start,fcrel.table[feature]),
	       SEEK_SET);

	 for (i=start;i<=end;i++) {

	    row = read_next_row(fcrel.table[feature]);

	    if (!set_member( i, feature_rows )) {
	       free_row(row,fcrel.table[feature]);
	       continue;
	    }

	    if (!set_member( i, tile_features )) {
	       free_row(row,fcrel.table[feature]);
	       continue;
	    }

	    if (degree == R_ONE) {
	       prim_rownum = fc_row_number( row, fcrel, tile );
	       primlist = NULL;
	       p = NULL;
	    } else {
	       primlist = fc_row_numbers( row, fcrel, tile, &idx );
	    }

	    free_row( row, fcrel.table[feature] );

	    if (!primlist) {
	       if ((prim_rownum<1)||
		   (prim_rownum>fcrel.table[prim].nrows))
		  continue;
	       if (set_member( prim_rownum, primitive_rows )) {
		  set_insert(prim_rownum,primitives[tile]);
	       }
	    } else {
	       p = ll_first(primlist);
	       while (!ll_end(p)) {
		  ll_element(p,&prim_rownum);
		  if ((prim_rownum<1)||
		      (prim_rownum>fcrel.table[prim].nrows))
		     continue;
		  if (set_member( prim_rownum, primitive_rows )) {
		     set_insert(prim_rownum,primitives[tile]);
		  }
		  p = ll_next(p);
	       }
	    }

	    if (kbhit()) {
	       if (getch()==27) {
		  *status = 0;
		  finished = 0;
		  break;
	       }
	    }
	 }

	 if (idx.fp) close_thematic_index(&idx);

	 vpf_close_table(&(fcrel.table[prim]));

	 set_nuke(&primitive_rows);

	 set_nuke(&tile_features);

	 if (set_empty(primitives[tile])) {
	    set_nuke(&primitives[tile]);
	    primitives[tile].size = 0;
	    primitives[tile].buf = NULL;
	 }

	 if (!finished) {
	    *status = 0;
	    break;
	 }

      }

      if (!finished) {
	 *status = 0;
	 deselect_feature_class_relate( &fcrel );
	 break;
      }

      if (found) *status = 1;

      if (kbhit()) {
	 if (getch()==27) {
	    *status = 0;
	    deselect_feature_class_relate( &fcrel );
	    break;
	 }
      }

      deselect_feature_class_relate( &fcrel );
   }

   set_nuke(&feature_rows);

   if (tilecover) {
      vpf_close_table(&tile_table);
   }

   return primitives;
}
コード例 #20
0
/**************************************************************************
 *
 *N  fc_row_numbers
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Given the starting row of a feature class relationship, return the
 *    list of row numbers of the table at the end of the feature class
 *    relate chain.
 *    If your relate goes from the feature to the primitive, this will
 *    return the primitive ids for the given feature row.
 *    If your relate goes from the primitive to the feature, this will
 *    return the feature ids of the given primitive row.
 *
 *    Currently only supports relates on 'I' or 'K' fields.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
linked_list_type fc_row_numbers( row_type row,
				 fcrel_type fcrel,
				 long int tile,
				 ThematicIndex *idx )
{
   row_type relrow;
   long int count;
   long int n, rownum, keyval;
   id_triplet_type triplet_keyval;
   int KEY1_, KEY_;
   position_type p, prow, pkey;
   vpf_relate_struct rcell;
   linked_list_type rowlist, keylist, templist;

   p = ll_first(fcrel.relate_list);
   ll_element(p,&rcell);
   KEY1_ = table_pos(rcell.key1,fcrel.table[0]);

   get_table_element(0,row,fcrel.table[0],&rownum,&count);

   if (KEY1_ == 0) {     /* "ID" */
      keyval = rownum;
   } else {
      switch (fcrel.table[0].header[KEY1_].type) {
	 case 'I':
	    get_table_element(KEY1_,row,fcrel.table[0],&keyval,&count);
	    break;
	 case 'K':
	    get_table_element(KEY1_,row,fcrel.table[0],&triplet_keyval,
			      &count);
	    keyval = triplet_keyval.exid;
	    if (tile != triplet_keyval.tile) {
	       keyval = -2;
	    }
	    break;
	 default:
	    keyval = 0;
	    break;
      }
   }

   keylist = ll_init();
   ll_insert(&keyval,sizeof(keyval),keylist);

   n = 0;

   p = ll_first(fcrel.relate_list);
   for (n=1;n<(fcrel.nchain-1);n++) {

      /* Relate through Join table(s) */

      rowlist = ll_init();
      pkey = ll_first(keylist);
      while (!ll_end(pkey)) {
	 ll_element(pkey,&keyval);
	 templist = related_rows(&keyval,fcrel.table[n],rcell.key2,0,NULL);
	 prow = ll_first(templist);
	 while (!ll_end(prow)) {
	    ll_element(prow,&rownum);
	    if (!ll_locate(&rownum,rowlist))
	       ll_insert(&rownum,sizeof(rownum),ll_last(rowlist));
	    prow = ll_next(prow);
	 }
	 ll_reset(templist);
	 pkey = ll_next(pkey);
      }
      ll_reset(keylist);

      p = ll_next(p);
      ll_element(p,&rcell);
      KEY_ = table_pos(rcell.key1,fcrel.table[n]);

      keylist = ll_init();
      prow = ll_first(rowlist);
      while (!ll_end(prow)) {
	 ll_element(prow,&rownum);
	 relrow = get_row(rownum,fcrel.table[n]);

	 if (KEY_ == 0) {     /* "ID" */
	    keyval = rownum;
	 } else {
	    switch (fcrel.table[n].header[KEY_].type) {
	    case 'I':
	       get_table_element(KEY_,relrow,fcrel.table[n],&keyval,&count);
	       break;
	    case 'K':
	       get_table_element(KEY_,relrow,fcrel.table[n],&triplet_keyval,
				 &count);
	       keyval = triplet_keyval.exid;
	       if (tile != triplet_keyval.tile) {
		  keyval = -2;
	       }
	       break;
	    default:
	       keyval = 0;
	       break;
	    }
	 }
	 if (keyval > 0)
	    ll_insert(&keyval,sizeof(keyval),ll_last(keylist));
	 prow = ll_next(prow);
	 free_row(relrow,fcrel.table[n]);
      }
      ll_reset(rowlist);
   }

   rowlist = ll_init();
   p = ll_first(keylist);
   while (!ll_end(p)) {
      ll_element(p,&keyval);
      templist = related_rows(&keyval,fcrel.table[n],rcell.key2,0,idx);
      prow = ll_first(templist);
      while (!ll_end(prow)) {
	 ll_element(prow,&rownum);
	 if (!ll_locate(&rownum,rowlist))
	    ll_insert(&rownum,sizeof(rownum),ll_last(rowlist));
	 prow = ll_next(prow);
      }
      ll_reset(templist);
      p = ll_next(p);
   }
   ll_reset(keylist);

   return rowlist;
}
コード例 #21
0
ファイル: ossimVpfTable.cpp プロジェクト: LucHermitte/ossim
ossimString ossimVpfTable::getColumnValueAsString(row_type& row,
                                                  long columnNumber)const
{
   ossimString result;
   ossim_int32 n=1;
   switch(theTableInformation->header[columnNumber].type)
   {
   case 'T': // it's of type text so
   {
      char c;
      char *buf = (char *)get_table_element(columnNumber,
                                            row,
                                            *theTableInformation,
                                            &c,
                                            &n);
      if(buf)
      {
         result = buf;
         free(buf);
      }
      else
      {
         result = c;
      }
      break;
   }
   case 'I':
   {
      ossim_int32 value;
      ossim_int32* v = (ossim_int32*)get_table_element(columnNumber,
                                                       row,
                                                       *theTableInformation,
                                                       &value,
                                                       &n);
      if(v)
      {
         result = ossimString::toString(v[0]);

         free(v);
      }
      else
      {
         result = ossimString::toString(value);
      }
      break;
   }
   case 'S':
   {
      short int value;
      short int* v = (short int*)get_table_element(columnNumber,
                                                   row,
                                                   *theTableInformation,
                                                   &value,
                                                   &n);
      if(v)
      {
         result = ossimString::toString(v[0]);

         free(v);
      }
      else
      {
         result = ossimString::toString(value);
      }
      break;
   }
   case 'F':
   {
      float value;
      float* v = (float*)get_table_element(columnNumber,
                                           row,
                                           *theTableInformation,
                                           &value,
                                           &n);
      if(v)
      {
         value = v[0];
         free(v);
      }
      if (!is_vpf_null_float(value))
      {
         result = ossimString::toString(value);
      }
      else
      {
         result = "nan";
      }
      break;
   }
   case 'B':
   {
      double value;
      double* tempBuf = (double*)get_table_element(columnNumber,
                                                 row,
                                                 *theTableInformation,
                                                 &value,
                                                 &n);
      if(tempBuf)
      {
         value = tempBuf[0];
         free(tempBuf);
      }
      if (!is_vpf_null_double(value))
      {
         result = ossimString::toString(value);
      }
      else
      {
         result = "nan";
      }

      break;
   }
   case 'C':
   {
      coordinate_type coordType;
      coordinate_type* temp = (coordinate_type*)get_table_element(columnNumber,
                                                                  row,
                                                                  *theTableInformation,
                                                                  &coordType,
                                                                  &n);
      if(temp)
      {
         coordType = temp[0];
         free(temp);
      }
      result = ossimString::toString(coordType.x)+
               ossimString(" ") +
               ossimString::toString(coordType.y);
      break;
   }
   case 'K':
   {
      id_triplet_type idTripletType;
      id_triplet_type* tempType = (id_triplet_type*)get_table_element(columnNumber,
                                                                      row,
                                                                      *theTableInformation,
                                                                      &idTripletType,
                                                                      &n);
      if(tempType)
      {
         idTripletType = tempType[0];
         free (tempType);
      }
      result = ossimString(idTripletType.type) +
         ossimString(" ") +
         ossimString::toString(static_cast<ossim_int32>(idTripletType.id)) +
         ossimString(" ") +
         ossimString::toString(static_cast<ossim_int32>(idTripletType.tile))+
         ossimString(" ") +
         ossimString::toString(static_cast<ossim_int32>(idTripletType.exid));
      break;
   }
   case 'D':
   {
      date_type date, formatDate;
      date_type* temp = (date_type*)get_table_element(columnNumber,
                                                      row,
                                                      *theTableInformation,
                                                      &date,
                                                      &n);
      if(temp)
      {
         free(temp);
      }
      format_date(date, formatDate);
      result = formatDate;
      break;
   }
   case 'Z': // tri coordinate types x, y, z
   {
      tri_coordinate_type  *tcptr=NULL;
      tcptr = (tri_coordinate_type *) get_table_element(columnNumber,row,
                                                        *theTableInformation, NULL,&n);
      result = "";
      for (int k=0;k<n;k++)
      {
         
         result = result + " (" +
            ossimString::toString(tcptr[k].x) +
            ossimString(" ") +
            ossimString::toString(tcptr[k].y) +
            ossimString(" ") +
            ossimString::toString(tcptr[k].z) +
            ossimString(") ") ;
      }
      
      if (tcptr)
      {
         free(tcptr);
      }
      break;
   }   
   }
   result.trim();
   return result;
}
コード例 #22
0
ファイル: vpfquery.c プロジェクト: vapd-radi/rspf_v2.0
/*************************************************************************
 *
 *N  query_table
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *     This function returns the set of selected rows of a VPF table
 *     based upon the evaluation of the given selection expression string.
 *
 *     The expression is strictly evaluated left to right.  No nesting
 *     is supported, so parentheses are not allowed.  The expression
 *     must match the form:
 *        <field><log op><value> [ <join> <field><log op><value>]
 *     where,
 *        <field> is a valid field name of the table.
 *        <log op> is one of the following: =, <, >, <=, >=, <> (not equal).
 *        <value> is a valid value for the field.
 *        <join> is either " AND " or " OR ".
 *     Any number of clauses (<field><log op><value>) may be joined
 *     together with AND or OR to form the expression.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    expression <input>==(char *) selection expression string.
 *    table      <input>==(vpf_table_type) VPF table structure.
 *    return    <output>==(set_type) set of selected rows.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels    May 1991                          DOS Turbo C
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   External Variables:
 *X
 *    None
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Functions Called:
 *F
 *    set_type set_init( rspf_int32 n ) SET.C
 *    void set_insert( rspf_int32 element, set_type set ) SET.C
 *    linked_list_type parse_expression( char *expression,
 *                     vpf_table_type table ) VPFQUERY.C
 *    row_type read_next_row( vpf_table_type table ) VPFREAD.C
 *    position_type ll_first( linked_list_type list ) LINKLIST.C
 *    int ll_end( position_type position ) LINKLIST.C
 *    void ll_element( position_type position, void *element ) LINKLIST.C
 *    void *get_table_element( rspf_int32 field_number,
 * 			 row_type row,
 *			 vpf_table_type table,
 *			 void *value,
 *			 rspf_int32  *count ) VPFREAD.C
 *    void display_message( char *info ) USER DEFINED
 *    static int strcompare( char *val1, char *val2, char op ) VPFQUERY.C
 *    static int icompare( rspf_int32 val1, rspf_int32 val2, char op ) VPFQUERY.C
 *    static int fcompare( float val1, float val2, char op ) VPFQUERY.C
 *    void ll_reset( linked_list_type list ) LINKLIST.C
      void free_row( row_type row, vpf_table_type table) VPFREAD.C
 *E
 *************************************************************************/
set_type query_table( char *expression, vpf_table_type table )
{
   row_type row;
   position_type pos;
   expr_type expr;
   register rspf_int32 i;
   int boolval=FALSE, booltemp=0, join = OR;
   rspf_int32 lval, lval2, count;
   float fval, fval2;
   char tval, tval2, *tptr;
   linked_list_type exprlist;
   set_type select_set;

   select_set = set_init(table.nrows+1);

   if (strcmp(expression,"*")==0) {
      set_on(select_set);
      return select_set;
   }

   exprlist = parse_expression( expression, table );

   if (!exprlist) return select_set;

   if (table.storage == DISK)
      fseek( table.fp, index_pos(1,table), SEEK_SET );

   for (i=1;i<=table.nrows;i++) {

      if (table.storage == DISK)
	 row = read_next_row(table);
      else
	 row = get_row( i, table );

      pos = ll_first(exprlist);
      while (!ll_end(pos)) {
	 ll_element( pos, &expr );
	 switch (table.header[expr.field].type) {
	    case 'I':
	       if (table.header[expr.field].count == 1) {
		  get_table_element( expr.field, row, table, &lval, &count );
		  lval2 = atol(expr.value);
		  booltemp = icompare( lval, lval2, expr.op );
	       } else {
		  display_message(
		     "Selection may not be performed upon arrays");
		  i=table.nrows+1;
	       }
	       break;
	    case 'T':
	       if (table.header[expr.field].count == 1) {
		  get_table_element( expr.field, row, table, &tval, &count );
		  tval2 = expr.value[0];
		  booltemp = comp( &tval, &tval2, sizeof(tval), expr.op );
	       } else {
		  tptr = (char *)get_table_element( expr.field, row, table,
				   NULL, &count );
		  booltemp = strcompare( tptr, expr.value, expr.op );
		  free(tptr);
	       }
	       break;
	    case 'F':
	       if (table.header[expr.field].count == 1) {
		  get_table_element( expr.field, row, table, &fval, &count );
		  if (!is_vpf_null_float(fval)) {
		     fval2 = (float)atof(expr.value);
		     booltemp = fcompare( fval, fval2, expr.op );
		  } else booltemp = FALSE;
	       } else {
		  display_message(
		     "Selection may not be performed upon arrays");
		  i=table.nrows+3;
	       }
	       break;
	    default:
	       display_message("Field type not supported for query");
	       i=table.nrows+3;
	       break;
	 }

	 if (i>table.nrows) break;

	 if (join==OR)
	    boolval = boolval || booltemp;
	 else
	    boolval = boolval && booltemp;

	 join = expr.join;

	 pos = pos->next;
      }
      free_row( row, table );
      if (boolval) set_insert(i,select_set);
      boolval = FALSE;
      join = OR;

      if (i==table.nrows+3) break;

   }

   ll_reset(exprlist);

   return select_set;
}
コード例 #23
0
ファイル: vpfdraw.c プロジェクト: LucHermitte/ossim
/*************************************************************************
 *
 *N  draw_face_row
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *     This function draws the specified face from the given row of
 *     the given face table.
 *     It is complicated by the fact that it checks to see whether a
 *     face has wrapped around the screen due to projection effects.
 *     If so, it first adjusts the coordinates off the right edge of the
 *     screen to fill that portion of the face.  Then, if the face
 *     wraps around to the other edge of the screen, it adjusts the
 *     coordinates to the left edge of the screen and refills to
 *     display that portion of the face.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     row       <input>==(row_type) row of the specified face table.
 *     facetable <input>==(vpf_table_type) VPF face primitive table.
 *     ringtable <input>==(vpf_table_type) VPF ring primitive table.
 *     edgetable <input>==(vpf_table_type) VPF edge primitive table.
 *     fbr       <input>==(vpf_table_type) VPF face bounding rectangle table.
 *     outline   <input>==(color_type) outline color.
 *     c1        <input>==(color_type) 1st color in the fill pattern.
 *     c2        <input>==(color_type) 2nd color in the fill pattern.
 *     c3        <input>==(color_type) 3rd color in the fill pattern.
 *     c4        <input>==(color_type) 4th color in the fill pattern.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   May 1991                           DOS Turbo C
 *E
 *************************************************************************/
void draw_face_row( row_type row,
		vpf_table_type facetable,
		vpf_table_type ringtable,
		vpf_table_type edgetable,
		vpf_table_type fbr,
		color_type outline,
		color_type c1,
		color_type c2,
		color_type c3,
		color_type c4 )
{
   ossim_int32 count;
   int  spx1,spy1,spx2,spy2,  rowid,ring;
   extent_type shade_box;
   Pattern  pattern;
   face_rec_type face_rec;
   int wrap, mbrx2;
   row_type fbrrow;
   int XMIN_,YMIN_,XMAX_,YMAX_;

   rowid = table_pos( "ID", facetable );
   ring = table_pos( "RING_PTR", facetable );
   get_table_element( rowid, row, facetable, &(face_rec.id), &count );
   get_table_element( ring, row, facetable, &(face_rec.ring), &count );

   gpsetlinecolor(outline);
   gpsetlinestyle(SOLID_LINE);
   gpsetlinewidth(NORM_WIDTH);

   wrap = 0;

   if (gpgetdevice()==SCREEN) {
      pattern = MakePattern(c1,c2,c3,c4);

      /* Read bounding box */
      fbrrow = read_row( face_rec.id, fbr );
      XMIN_ = table_pos( "XMIN", fbr );
      YMIN_ = table_pos( "YMIN", fbr );
      XMAX_ = table_pos( "XMAX", fbr );
      YMAX_ = table_pos( "YMAX", fbr );
      get_table_element(XMIN_,fbrrow,fbr,&shade_box.x1,&count);
      get_table_element(YMIN_,fbrrow,fbr,&shade_box.y1,&count);
      get_table_element(XMAX_,fbrrow,fbr,&shade_box.x2,&count);
      get_table_element(YMAX_,fbrrow,fbr,&shade_box.y2,&count);
      free_row(fbrrow,fbr);

      screen_bounds(shade_box.x1,shade_box.y1,
		 shade_box.x2,shade_box.y2,
		 &spx1,&spy1,&spx2,&spy2);
      mbrx2 = spx2;
      if (spx2<spx1) {
	 /* The face wraps around the screen */
	 /* (or at least wraps off the edge of the screen) */
	 wrap = gpgetmaxx();
	 if (spx2 < 0) wrap -= spx2;
	 /* Adjust the maximum screen value */
	 spx2 += wrap;
      }

   } else {
      gpstartpoly();
   }

   draw_polygon( spx1,spy1,spx2,spy2, face_rec, ringtable,
		 edgetable, outline, pattern, wrap );

   if (wrap && mbrx2 > 0) {
      /* The polygon has wrapped around to the other side of the */
      /* screen.  Must redraw the part left off on the first pass. */

      if (gpgetdevice()==SCREEN) {

	 spx1 -= wrap;
	 spx2 -= wrap;

      } else {
	 gpstartpoly();
      }

      wrap *= -1;
      draw_polygon( spx1,spy1,spx2,spy2, face_rec, ringtable,
		    edgetable, outline, pattern, wrap );

   }

}