|
阅读:1334回复:1
请教:ArcEngine中UniqueValueRenderer的显示问题? 急!!
<P>请教:ArcEngine中为何对UniqueValueRenderer中的值进行排序后图像就不能显示,我用VC开发。同样的代码,只是在UniqueValueRenderer加载值之前对其进行排序,并按顺序加入值,在显示时能在TOC中看到加入了图层,但是mapcontrol中不能显示。如果不排序就可以在mapcontrol显示。请教各位达人,这种问题如何解决?以下是排序后render的代码:</P>
<P>void XAddDataAPI::RenderPolygonLayer(IFeatureLayerPtr ipFeatureLayer)<BR>{<BR>CString szAppPathName;<BR>szAppPathName = XAddDataAPI::GetAppPathName();<BR><BR>IStyleGalleryStoragePtr ipStyleGalleryStorage(CLSID_ServerStyleGallery);<BR>CString szStyleName;szStyleName = szAppPathName + "<A>\\Weather.serverStyle</A>";<BR>HRESULT hr;<BR>hr = ipStyleGalleryStorage->put_TargetFile(_bstr_t(szStyleName));<BR>//hr = ipStyleGallery->LoadStyle(_bstr_t(szStyleName), _bstr_t("Color Ramps"));<BR>if(FAILED(hr))<BR>{<BR>// AfxMessageBox(_T("加载颜色方案出错!"));return;<BR>}<BR>IStyleGalleryPtr ipStyleGallery(ipStyleGalleryStorage);<BR>IEnumStyleGalleryItemPtr ipEnumStyleGalleryItem;<BR>ipStyleGallery->get_Items(_bstr_t("Color Ramps"), 0, _bstr_t("Default"), ;ipEnumStyleGalleryItem);<BR><BR>IStyleGalleryItemPtr ipStyleGalleryItem;<BR>ipEnumStyleGalleryItem->Next(;ipStyleGalleryItem);<BR>IUnknownPtr ipUnknown;<BR>while(ipStyleGalleryItem)<BR>{<BR> BSTR bstrNames;<BR> ipStyleGalleryItem->get_Name(;bstrNames);<BR> CString szName; szName = bstrNames;<BR> if(szName.CompareNoCase("Radar Loop Rain") == 0)<BR> {<BR> <BR> ipStyleGalleryItem->get_Item(;ipUnknown);<BR> break; <BR> }<BR> ipEnumStyleGalleryItem->Next(;ipStyleGalleryItem);<BR>}<BR>if(ipUnknown == NULL)<BR> return ;<BR>IColorRampPtr ipColorRamp(ipUnknown);<BR><BR>IUniqueValueRendererPtr ipUniqueValueRenderer(CLSID_UniqueValueRenderer);<BR>ipUniqueValueRenderer->put_FieldCount(1);<BR>ipUniqueValueRenderer->put_Field(0, _bstr_t("FValueDesc"));<BR>IDataStatisticsPtr ipDataStatistics(CLSID_DataStatistics);<BR>ipDataStatistics->put_Field(_bstr_t("FValueDesc"));<BR>IFeatureCursorPtr ipCursor;<BR>ipFeatureLayer->Search(NULL, VARIANT_TRUE, ;ipCursor);<BR>ICursorPtr ipCursor2(ipCursor);<BR>ipDataStatistics->putref_Cursor(ipCursor2);<BR>IEnumVARIANTPtr values;<BR>ipDataStatistics->get_UniqueValues(;values);<BR>long count;<BR>ipDataStatistics->get_UniqueValueCount(;count);<BR>if(values == NULL)<BR> return ;<BR>IEnumVariantSimplePtr ipValues(values);<BR>ipValues->Reset();<BR>VARIANT var;<BR>ipValues->Next(;var);<BR>int k =0;<BR>CMyItemArray array;<BR>array.m_ipdblsAry.RemoveAll();<BR>while(k < count)<BR>{<BR> CString szValue = var.bstrVal;<BR> szValue.TrimLeft();szValue.TrimRight();<BR> if(szValue.IsEmpty())<BR> {<BR> ITEM item;<BR> item.szItem = szValue;<BR> item.value = -100000;<BR> array.Add(item);<BR> }<BR> else<BR> {<BR> int pos2 = szValue.Find('<');<BR> long len = szValue.GetLength();<BR> ITEM item;<BR> if(pos2 > -1)<BR> {<BR> item.value = -50000; <BR> item.szItem = szValue;<BR> }<BR> int npos = szValue.Find('-');<BR> if(npos > -1)<BR> {<BR> CString sz = szValue.Left(npos);<BR> CString szValue2 = szValue.Right(len-npos-1);<BR> double a,b;a= atof(sz.GetBuffer(sz.GetLength()));<BR> b = atof(szValue2.GetBuffer(szValue2.GetLength()));<BR> item.value = (a+b)/2+b;<BR> item.szItem = szValue;<BR> }<BR> pos2 = szValue.Find('>');<BR> if(pos2 >-1)<BR> {<BR> item.value = 100000; <BR> item.szItem = szValue;<BR> }</P> <P> array.Add(item);<BR> }<BR> ipValues->Next(;var);<BR> k++;<BR>}<BR>ipColorRamp->put_Size(count);<BR>VARIANT_BOOL vb;<BR>ipColorRamp->CreateRamp(;vb);<BR>IEnumColorsPtr ipEnumColors;<BR>ipColorRamp->get_Colors(;ipEnumColors);<BR>IColorPtr ipColorPtr;<BR>ipEnumColors->Reset();<BR>ipEnumColors->Next(;ipColorPtr);<BR><BR>array.ArrayCompositor(); //此处对数组进行排序的函数<BR>long szz = array.m_ipdblsAry.GetCount();<BR>POSITION pos = array.m_ipdblsAry.GetHeadPosition();<BR>int i =0;</P> <P><BR>while(i < szz)<BR>{<BR> ITEM item = array.m_ipdblsAry.GetAt(pos);<BR> <BR> ISimpleFillSymbolPtr ipSimpleFillSymbol(CLSID_SimpleFillSymbol);<BR> ipSimpleFillSymbol->put_Color(ipColorPtr);<BR> ISymbolPtr ipSymbol(ipSimpleFillSymbol);<BR> ipUniqueValueRenderer->AddValue(_bstr_t(item.szItem), NULL, ipSymbol);<BR><BR> ipEnumColors->Next(;ipColorPtr);<BR> array.m_ipdblsAry.GetNext(pos);<BR> i++; <BR> <BR>}<BR>IGeoFeatureLayerPtr ipGeoFeatureLayer(ipFeatureLayer);<BR>IFeatureRendererPtr ipFeatureRenderer(ipUniqueValueRenderer);<BR>ipGeoFeatureLayer->putref_Renderer(ipFeatureRenderer);</P> <P>}</P> |
|
|
1楼#
发布于:2006-06-16 23:28
<P>没仔细看,我只是觉得,有可能是因为你的render变量是局部变量,改成全局的试试</P>
|
|