Category Archives: GIS

GeneratePolygonsByPoints utility

Purpose: to generate polygons (rectangles) by connecting neighboring points

Author: Zhuotong Nan
Email: [email protected]
Date: Nov 21, 2007

ver: 1.0.0

Usage: GeneratePolygonsByPoints [data_file_name] {output shapefile name}
Rows*Cols (for ex, 260*250): (enter numbers of rows and cols for the source data file with
a format rows*cols. Incorrect input will stop the tool.)

data_file_name: source data file name; path can be included.
output shapefile name: optional, as its literal stated. path can be includes.

Supporting environment: Microsoft dotnet framework 2.0, ArcGIS 9.2 with dotnet assemblies, as
well as a valid ArcInfo license.

Remarks: Data file should be organized row by row (you should know exact row and column
number, which will be required to be entered after starting), starting from lower left corner.
In my initial case, the data file is generated by a modified Read_XMRG2 utility for XMRG
radar data file. The modified Read_XMRG2 will generate data with geographical coordinates
instead of HRAP coordinates as does original Read_XMRG2. Anyway, GeneratePolygonsByPoints
will also run against data file generated by original Read_XMRG2, however, with output
shapefile being in HRAP coordination.

Data file content looks like following:

-121.177570 37.897155 0.000000
-121.132468 37.907464 0.000000
-121.087345 37.917746 0.000000
-121.042201 37.928001 0.000000
-120.997037 37.938229 0.000000

The first column is longitude, second latitude, and the third precipitation value. The first
two columns represent that cells’ lower left coordinations. The first row indicates the lower
left cell; second is the next cell right to the first cell; after finishing a row, then begin
a row up the first row, and move upwards.

Output shapefile will be of geographic NAD83 datum. The first two columns will be converted
to points’ geographic location. Values (precp value in above example) will be lost. A new
field named "Index" will be generated to record this polygon’s lower left corner’s coordination
with a format of "lat_lon", for ex. 37.897155_-121.177570 for the first created cell. However,
you cannot depend on this field to link original source data file. In order to do link, you can
"ID" field in shapefile attribute table, which increases by one in consitence with source data
file.

As stated above, each cell is referred by its lower left corner’s coordination. The most upper
cells cannot be generated due to missing of necessary points (we only have lower edge’s
coord). Likewise, the most right cells are also missed.

The distribution also includes a test data file: xmrg0101199900z.out, with a 39*48 (rows*cols)
dimension.

For more information, please contact the author at [email protected]

ArcIMS ArcXML 元数据搜索中文关键词问题

或者在c#代码中直接用中文字符构建 SEARCH_METADATA将搜索失败,提示非法的ArcXML
解决方法是使用中文的unicode表示,即旞类似的方式
提供了一个转换函数:

/// <summary>
/// 将汉字变成 黑&27827;的ascii编码
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string UnicodeEncode(string text)
{
char[] chars = System.Web.HttpUtility.HtmlEncode(text).ToCharArray();
System.Text.StringBuilder result = new System.Text.StringBuilder(text.Length + (int)(text.Length * 0.1));

foreach (char c in chars)
{
int value = Convert.ToInt32(c);
if (value > 127)
result.AppendFormat("&#{0};", value);
else
result.Append(c);
}

return result.ToString();
}

ESRI本身提供的metadata explorer搜索中文关键词时有问题,是因为它的代码将中文解释成了 &amp;26789;类似,而不是梥,可能是将&再次解释了,搜索时将不返回结果。不知道9.1及以后版本的arcims metadata explorer里是否已经更正。

ArcCatalog使用iso元数据标准

为了系统只使用iso标准,ArcCatalog(以下称ac)做为发布端,需要做如下工作:

  1. 关闭fgdc和geo-network同步器。在metata菜单里,使用set working synchronizer命令关闭两者。
  2. 建立一个vba宏,删除xml里的fgdc标签。edn有现成可用的宏,在esri的edn开发网站上搜索 delete FGDC metadata,估计就可以找到。(或向我索要)建立好了,在ac里选择上需要处理的文档,支持宏即好。其实分析一下,就只有几个标签,手工去删除也不难。而且最好能有个自己的工具去批量删除。
  3. 关闭 arcims server上的基于内容的 validation功能,用处不大,那是为metadata explorer设计的,如果不用explorer,这个功能就没多大用处了,而且此功能实质是检查 fgdc标签的内容(或者说iso的内容处在低于fgdc内容的优先级别上)。

SQL server master库损坏的解决方案

SQL server 2k master db corruption due to power cutoff, causing sql server cannot start up. In this server, ArcSDE 9 and ArcIMS 9 are associated with Sql Server 2k sp4. and worse, no backup have been created prior to this disaster.
solution:
1. Backup possibly effected dbs, i.e., sde db, and westdc db.
2. run rebuildm.exe to reconstruct the master db. all logins are lost after that operation. sde amd westdc dbs cannot be found in the rebuilt master db.
3. attach the original sde db and westdc db using sa as the db owner.
4. create lost logins, for example, westdc, sde, etc. Fortunately, I have backed up all these information.
5. using enterprise manager, open sde and westdc dbs, isolated users can be found under the users leaf. So we have to assign the appropriate logins to those isolated users. use commands as follow:
USE sde;
GO
sp_change_users_login @Action=’Report’;
GO
USE westdc;
GO
sp_change_users_login @Action=’update_one’, @UserNamePattern=’westdc’, @LoginName=’westdc’;
GO
the first set of commands is used to report the isolated users in database sde. the second set of commands will assign an existing login named westdc to the isolated user westdc.
6. restart the arcsde service, then arcims services. DONE!
Lessons:
We always are required to backup databases in a regular interval.

南宅影像图

最近google Earth更新了一些数据,浏览到我家的时候,发现可能是由于附近有个海事边哨,覆盖我老家的是一景分辨率较高的影像(估计是QuickBird这类),可以分辨到我们家的屋顶,剪裁下来与大家共享。

IMapPtr在vc里编译提示没定义

上午有人问在他的MFC程序里,为什么IMapPtr不能用,在编译的时候说没定义。
首先我们要明白IMapPtr是什么东西,在COM里,有一种叫智能指针(smart pointer),通过此类指针,COM可以安全地构造和析构。一般通过_COM_SMARTPTR_TYPEDEF(<interface>, __uuidof(<interface>))宏来定义,对IMap扩展后相当于:
typedef _com_ptr_t<_com_IIID<IMap, __uuidof(IMap)>> IMapPtr;
这部分工作在vc里导入 type library时完成,vc通过 #import来完成,import会自动生成 .tlh和.tli,这些typedef即在 .tlh里定义。
在ArcEngine编程中,一般在vc环境设置中include进 ArcSDK.h,和*.olb所在目录,在stdafx.h里增加 #include <ArcSDK.h>后,就可以在代码中直接用象IMapPtr这类指针了。
包括ArcSDK.h时要求事先定义ESRI_WINDOWS,这样arcsdk.h事实是调用 windows_sdk.h,编译时可能会有一些警告,可以忽略,或者通过#pragma warning(disable : 4192) 来忽略特定的警告。
 
如果上述工作后仍有问题,你应该有理由怀疑你的ArcEngine安装可能不完整了。

ArcGIS installation error 1904

With prompt like failed to register.

Solution: this is due to the embedded DEP (data execution protection). Change the parameter of boot.ini “NoExecute=OptIn” to “NoExecute=AlwaysOff” to work around this problem. After installation, please set it back to OptIn.

ArcGIS License server & firewall

为使得ArcGIS License Server通过 windows firewall 被其它机器所使用,需要如下 配置:
1. open License.dat or *.lic obtained from ESRI company,remember the port specified in the host line, commonly 27000, or 27004
2. specify the port used by arcgis.exe, for ex.
VENDOR ARCGIS PORT=1234 
(in my computer, it is 1025 by default)
3. open your firewall configuration window, add ports for manager (as item 1), 
as well as for arcgis.exe (as item 2) respectively
 
done!
 
 

arcCatalog不能通过ip address访问 sde spatial db

在arcCatalog里的spatial database connection对话框里,不能通过 ip address连接
到sde,但域名是可以的
解决方法:在本机的hosts(%system32%driversetc)文件里添加一行:
210.77.68.241 geodata #arcsde server
再在catalog里连接,使用ip或geodata都可以连接上去。

可能的原因:catalog在输入ip地址时,使用了getHostByAddr()方法,得到域名后,再
执行正常的连接(从host->ip->连接)。由于210.77.68.241这个ip没能反解得到域
名,故连接失败。
增加hosts项后,getHostByAddr可以反解得到域名是geodata,正常连接的时候,再行
解释域名到ip,从而正常连接。

评价:比较ugly的方法,如果不反解,而直接根据ip进行连接估计更好。可能是受
catalog采用的编程语言本身api的限制。