阅读:1575回复:2
mo数据操作数度提高的方法
<P>我发现当把图层文件加入到图层中以后,对其数据进行操作速度很慢。</P>
<P>特别是进行空间统计的时候,从一个原图层数据过滤出符合条件的数据添加到统计结果中,我采用下面方法,速度会提高好多。</P> <P>//CreateShpFile中只创建图层,而不把它加入到MAP中。</P> <P>CMoMapLayer CreateShpFile(CString ShpFilePath, int ShpFileStyle,vector<lpMoFieldInfo> fieldDesc)<BR>{<BR> Logf("创建SHAPE文件:%s.....",ShpFilePath);<BR> CMoDataConnection conn;<BR> if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection")))<BR> {<BR> Logf("失败!Error:%s\n",TEXT("创建连接失败"));<BR> return NULL;<BR> }<BR> CString strFileTitle( ShpFilePath );<BR> int idx = 0;<BR> while ( idx != -1 )<BR> {<BR> idx = strFileTitle.Find( "\\" );<BR> strFileTitle = strFileTitle.Right( strFileTitle.GetLength() - idx - 1 );<BR> }<BR> idx = ShpFilePath.Find( strFileTitle );<BR> CString strFilePath( ShpFilePath.Left( idx ) );<BR> conn.SetDatabase( strFilePath );<BR> if (!conn.Connect())<BR> {<BR> Logf("失败!Error:%s\n",TEXT("连接失败"));<BR> return NULL;<BR> }<BR> CMoTableDesc tDesc;<BR> if (!tDesc.CreateDispatch(TEXT("MapObjects2.TableDesc")))<BR> {<BR> Logf("失败!Error:%s\n",TEXT("创建表失败"));<BR> return NULL;<BR> }<BR> tDesc.SetFieldCount(fieldDesc.size());<BR> vector<lpMoFieldInfo>::const_iterator itor;<BR> int index = 0;<BR> for(itor = fieldDesc.begin();itor != fieldDesc.end();++itor)<BR> {<BR> if((*itor)->fieldType == moString)<BR> {<BR> tDesc.SetFieldType(index,moString);<BR> tDesc.SetFieldName(index, (*itor)->fieldName);<BR> tDesc.SetFieldLength(index, (*itor)->fieldLength);<BR> }<BR> else if((*itor)->fieldType == moLong)<BR> {<BR> tDesc.SetFieldType(index,moLong);<BR> tDesc.SetFieldName(index, (*itor)->fieldName);<BR> tDesc.SetFieldPrecision(index, (*itor)->fieldPrecision);<BR> }<BR> else if((*itor)->fieldType == moDouble)<BR> {<BR> tDesc.SetFieldType(index,moDouble);<BR> tDesc.SetFieldName(index,(*itor)->fieldName);<BR> tDesc.SetFieldPrecision(index,(*itor)->fieldPrecision);<BR> tDesc.SetFieldScale(index, (*itor)->fieldScale);<BR> }<BR> index++;<BR> }</P> <P> VARIANT vt;<BR> vt.vt = VT_BOOL;<BR> vt.boolVal = VARIANT_FALSE;<BR> CMoGeoDataset Geoset(conn.AddGeoDataset(strFileTitle, ShpFileStyle,(LPDISPATCH)tDesc, vt, vt));</P> <P> CMoMapLayer TempMapLayer;<BR> if (!TempMapLayer.CreateDispatch(TEXT("MapObjects2.MapLayer")))<BR> {<BR> Logf("失败!Error:%s\n",TEXT("创建图层失败"));<BR> return NULL;<BR> }</P> <P> TempMapLayer.SetGeoDataset(Geoset);<BR> Logf("成功!\n");</P> <P> return TempMapLayer;<BR>}</P> <P> CMoMapLayer tempPolyLayer(CreateShpFile(tempPolyShpFile,moShapeTypePolygon,tempPolyFieldInfo));<BR> tempPolyLayer.SetCoordinateSystem(m_map->GetCoordinateSystem());<BR> CMoRecordset tempPolyResc = tempPolyLayer.GetRecords();</P> <P>。。。。</P> <P>tempPolyResc.AddNew();</P> <P>tempPolyResc.Update();</P> <P>....</P> |
|
1楼#
发布于:2006-04-09 15:59
<P>看一下</P>
|
|
2楼#
发布于:2006-04-25 16:46
<P>我用C#,看不大懂你的。</P><img src="images/post/smile/dvbbs/em02.gif" />
|
|