Arcengine C # Load layer data within the administrative region

Source: Internet
Author: User
  1. During normal development, you may encounter the need to load layer data by administrative region. For example, the entire Ministry of Land and Resources has a certain type of thematic data with several layers, and each layer has a data range of China, at this time, the Ministry of Land and Resources may need to develop a system. Each province can only load data from this province. The following function creates a layer for the administrative region according to the administrative region.
  2. For example, if you want to obtain the data of Henan Province, you only need to input the Geometry of the Henan Provincial element in the administrative area layer. In addition, if the administrative layer must be esriSpatialRelEnum. esriSpatialRelContains. Otherwise, the administrative region cannot only obtain the province of Henan. It will take the provinces around Henan, Hebei, Hubei, Anhui, Shaanxi, and Shandong, the elements of the Province, such as Shanxi province, are also added to the new layer.
  3. /// <Summary>
  4. /// Create a layer within the administrative region according to the Administrative Region
  5. /// </Summary>
  6. /// <Param name = "pFeatureLayer"> source data layer </param>
  7. /// <Param name = "pGeometry"> Administrative Region </param>
  8. /// <Param name = "bXZQ"> whether the layer is an administrative region </param>
  9. /// <Returns> new layer </returns>
  10. PrivateIFeatureLayer GetSelectionLayer (IFeatureLayer pFeatureLayer, IGeometry pGeometry,BoolBXZQ)
  11. {
  12. Try
  13. {
  14. If(PFeatureLayer! =Null& PGeometry! =Null)
  15. {
  16. IQueryFilter pQueryFilter;
  17. ISpatialFilter pSpatialFilter =NewSpatialFilterClass ();
  18. IFeatureSelection pFeatureSelection = pFeatureLayerAsIFeatureSelection;
  19. PSpatialFilter. GeometryField = pFeatureLayer. FeatureClass. ShapeFieldName;
  20. PFeatureSelection. Clear ();
  21. If(! BXZQ)
  22. {
  23. PSpatialFilter. Geometry = pGeometry;
  24. PSpatialFilter. SpatialRel = esriSpatialRelEnum. esriSpatialRelIntersects;
  25. PQueryFilter = pSpatialFilter;
  26. PFeatureSelection. SelectFeatures (pQueryFilter, esriSelectionResultEnum. esriSelectionResultNew,False);
  27. }
  28. Else
  29. {
  30. PSpatialFilter. SpatialRel = esriSpatialRelEnum. esriSpatialRelContains;
  31. PQueryFilter = pSpatialFilter;
  32. If(PGeometryIsIGeometryCollection)
  33. {
  34. For(IntI = 0; I <(pGeometryAsIGeometryCollection). GeometryCount; I ++)
  35. {
  36. PSpatialFilter. Geometry = (pGeometryAsIGeometryCollection). get_Geometry (I );
  37. PFeatureSelection. SelectFeatures (pQueryFilter, esriSelectionResultEnum. esriSelectionResultAdd,False);
  38. }
  39. }
  40. }
  41. IFeatureLayerDefinition pFLDefinition = pFeatureLayerAsIFeatureLayerDefinition;
  42. IFeatureLayer pNewFeatureLayer = pFLDefinition. CreateSelectionLayer (pFeatureLayer. Name,True,Null,Null);
  43. PNewFeatureLayer. MaximumScale = pFeatureLayer. MaximumScale;
  44. PNewFeatureLayer. MinimumScale = pFeatureLayer. MinimumScale;
  45. PNewFeatureLayer. Selectable = pFeatureLayer. Selectable;
  46. PNewFeatureLayer. Visible = pFeatureLayer. Visible;
  47. PNewFeatureLayer. ScaleSymbols = pFeatureLayer. ScaleSymbols;
  48. ReturnPNewFeatureLayer;
  49. }
  50. Else
  51. {
  52. Return Null;
  53. }
  54. }
  55. Catch(Exception Err)
  56. {
  57. MessageBox. Show (Err. Message, "Get SelectionLayer", MessageBoxButtons. OK, MessageBoxIcon. Information );
  58. Return Null;
  59. }
  60. }
  61. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.