public bool Work() { if (!Init()) { return(false); } IFeatureCursor cursor = _polygonFeatureClass.Insert(true); IFeatureCursor featurecursor = _polylineFeatureClass.Search(null, false); IFeature feature = featurecursor.NextFeature(); while (feature != null) { if (PolylineManager.IsPolygon(feature)) { var pg = PolylineManager.GeneratePolygon(feature.ShapeCopy); if (pg != null) { var buffer = _polygonFeatureClass.CreateFeatureBuffer(); buffer.Shape = pg; for (var i = 0; i < feature.Fields.FieldCount; i++) { IField field = feature.Fields.get_Field(i); if (field != null) { if (field.Name == "OID" || field.Name == "FID" || field.Name.ToUpper() == "SHAPE" || field.Name.ToUpper().Contains("SHAPE")) { continue; } var val = feature.get_Value(i); var index = buffer.Fields.FindField(field.Name); if (index > -1) { buffer.set_Value(index, val); } } } try { object featureOID = cursor.InsertFeature(buffer); cursor.Flush(); }catch (Exception ex) { _error += string.Format("存在保存到总FeatureCLass错误,错误信息:{0}", ex.ToString()); } } } feature = featurecursor.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); System.Runtime.InteropServices.Marshal.ReleaseComObject(featurecursor); return(string.IsNullOrEmpty(_error)); }
protected override void startDemo(bool isRestore) { if (!isRestore) { getMap().MoveCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(51.403186, -0.126446), 10)); } // Shared object managers - used to support multiple layer types on the map simultaneously MarkerManager markerManager = new MarkerManager(getMap()); GroundOverlayManager groundOverlayManager = new GroundOverlayManager(getMap()); PolygonManager polygonManager = new PolygonManager(getMap()); PolylineManager polylineManager = new PolylineManager(getMap()); // Add clustering mClusterManager = new ClusterManager(this, getMap(), markerManager); getMap().SetOnCameraIdleListener(mClusterManager); try { readClusterItems(); } catch (JSONException e) { Toast.MakeText(this, "Problem reading list of markers.", ToastLength.Long).Show(); e.PrintStackTrace(); } // Add GeoJSON from resource try { var geoJsonOnFeatureClickListener = new GeoJsonOnFeatureClickListener(this); // GeoJSON polyline GeoJsonLayer geoJsonLineLayer = new GeoJsonLayer(getMap(), Resource.Raw.south_london_line_geojson, this, markerManager, polygonManager, polylineManager, groundOverlayManager); // Make the line red GeoJsonLineStringStyle geoJsonLineStringStyle = new GeoJsonLineStringStyle(); geoJsonLineStringStyle.Color = Color.Red; foreach (GeoJsonFeature f in geoJsonLineLayer.Features.ToEnumerable()) { f.LineStringStyle = geoJsonLineStringStyle; } geoJsonLineLayer.AddLayerToMap(); geoJsonLineLayer.SetOnFeatureClickListener(geoJsonOnFeatureClickListener); // GeoJSON polygon GeoJsonLayer geoJsonPolygonLayer = new GeoJsonLayer(getMap(), Resource.Raw.south_london_square_geojson, this, markerManager, polygonManager, polylineManager, groundOverlayManager); // Fill it with red GeoJsonPolygonStyle geoJsonPolygonStyle = new GeoJsonPolygonStyle(); geoJsonPolygonStyle.FillColor = Color.Red; foreach (GeoJsonFeature f in geoJsonPolygonLayer.Features.ToEnumerable()) { f.PolygonStyle = geoJsonPolygonStyle; } geoJsonPolygonLayer.AddLayerToMap(); geoJsonPolygonLayer.SetOnFeatureClickListener(geoJsonOnFeatureClickListener); } catch (Java.IO.IOException) { Log.Error(TAG, "GeoJSON file could not be read"); } catch (JSONException) { Log.Error(TAG, "GeoJSON file could not be converted to a JSONObject"); } // Add KMLs from resources KmlLayer kmlPolylineLayer; KmlLayer kmlPolygonLayer; try { var kmlLayerOnFeatureClickListener = new KmlLayerOnFeatureClickListener(this); // KML Polyline kmlPolylineLayer = new KmlLayer(getMap(), Resource.Raw.south_london_line_kml, this, markerManager, polygonManager, polylineManager, groundOverlayManager, null); kmlPolylineLayer.AddLayerToMap(); kmlPolylineLayer.SetOnFeatureClickListener(kmlLayerOnFeatureClickListener); // KML Polygon kmlPolygonLayer = new KmlLayer(getMap(), Resource.Raw.south_london_square_kml, this, markerManager, polygonManager, polylineManager, groundOverlayManager, null); kmlPolygonLayer.AddLayerToMap(); kmlPolygonLayer.SetOnFeatureClickListener(kmlLayerOnFeatureClickListener); } catch (XmlPullParserException e) { e.PrintStackTrace(); } catch (Java.IO.IOException e) { e.PrintStackTrace(); } // Unclustered marker - instead of adding to the map directly, use the MarkerManager MarkerManager.Collection markerCollection = markerManager.NewCollection(); markerCollection.AddMarker(new MarkerOptions() .SetPosition(new LatLng(51.150000, -0.150032)) .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueAzure)) .SetTitle("Unclustered marker")); markerCollection.SetOnMarkerClickListener(this); }