Tag Archives: c

Arcinfo Generate 格式转Shapefile 的方法

Arc/Info Generate 格式已经有点历史,现在版本的ArcMap 都不能直接支持对该格式的读取。但由于Generate 格式对矢量数据模型的表达十分简明,在教学中仍然还广泛提及。为了看看Generate 文件的地图效果,需要把该格式转为Shapefile 等格式,才能在ArcMap 中显示。

第一种转换的方法是使用ArcGIS 的Data Interoperability 模块

ArcGIS Desktop 里需要安装 Data Interoperability 模块,在ArcMap Extension 里将该模块打勾,然后通过 ArcToolbox 下的 Data Interoperability Tools 里的Quick Import 将Generate 文件导入到Shapefile 或者 Geodatabase。

Data Interoperability 实际上是调用了内置的FME Reader 来实现格式互转,ArcInfo Generate 的短名是ARCGEN。如果Generate 文件后缀是.gen,在import时可以被自动识别;如果不是.gen,则需要手动设置输入格式是ARCGEN。

第二种转换方法是使用第三方工具 gen2shp (提供可执行文件下载)

Continue reading

在C中调用Fortran中的字符串数组

modparm.f

!在此模块下定义了很多共用变量,此处以title为例,定义为60个数组,每数组包括4字符

      module parm
      character(len=4) :: title(60), cpnm(5000)
      end module parm

getallo.f

!此函数(子例程)将使用modparm.f中定义的title变量,将从file.cio文件中读取3行填充title

      subroutine getallo
      use parm

!!    initialize variables
!      write(*,*) title
      title = “”

      open (23,file=”file.cio”)
      read (23,6000) titldum
      read (23,6000) titldum
      read (23,5100) title
      read (23,6000) titldum
      read (23,5000) figfile
      read (23,*) myr

      close (23)
      return
5000 format (6a)
5100 format (20a4)
6000 format (a80)
       end

将两fortran文件使用gfortran联编成 dll ,此时,title的实际符号为 __parm_MOD_title,getallo的实际符号为 getallo_。

在Qt/C++代码中读取和修改 title 变量,两个方法,如下:

1. 直接申明外部变量

#include <QtCore/QCoreApplication>
#include <QDebug>

extern “C” char __parm_MOD_title[60][4];
extern “C” void getallo_();

int main1(int argc, char *argv[])
{

     getallo_();
    char* aa = new char[60*4 +1];

    memcpy(aa, __parm_MOD_title, 60*4);
    aa[240]=”;

    qDebug()<<“__parm_MOD_title:”<<
            aa;
}

同样可以通过数组访问的方式对元素进行修改。

2. 通过动态加载resolve方法

#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QLibrary>

extern “C” void getallo_();

int main(int argc, char *argv[])
{
    char * title =(char *)QLibrary::resolve(“../bin/test.dll”,”__parm_MOD_title”);

     getallo_();
    char* aa = new char[60*4 +1];
aa[240]=”;

    memcpy(aa, title, 60*4);

    qDebug()<<“__parm_MOD_title:”<<
            aa;

//修改第一个字符
title[0]=’h’;
   memcpy(aa, title, 60*4);
   qDebug()<<“__parm_MOD_title:”<<
           aa;
}

第二种方法将多维数组作为一维数组进行访问。