Post Params list -
Tuesday, February 6, 2018
Monday, February 5, 2018
Friday, February 2, 2018
[Code snippet] Extract Feature Layer Fields from Map Document (Mxd) using ArcPy
This code snippet is for getting a list of fields in a feature layer from a map document in ArcPy 10.4.
1: #Import arcpy mapping library
2: import arcpy.mapping;
3:
4: # Map doc path
5: mxdPath =r"C:\MyMxd.mxd"
6:
7: #Open map document
8: document = arcpy.mapping.MapDocument(mxdPath)
9:
10: #Extract all dataframes inside a map document
11: dataFrameList = arcpy.mapping.ListDataFrames(document)
12:
13: #Loop through all DF
14: for dataFrame in dataFrameList:
15: #Extact all layers in a dataframe
16: layerList = arcpy.mapping.ListLayers(document, None, dataFrame)
17:
18: #Loop through all Layers
19: for layer in layerList:
20: print (dataFrame.name+"--"+layer.name +"--"+layer.dataSource)
21:
22: #Extract all fields in a layer
23: fieldList = arcpy.ListFields(layer.dataSource, None, None)
24:
25: #Loop through and print field properties
26: for field in fieldList:
27: print(field.name,field.aliasName,field.type,field.length,field.required,field.precision)
Code Snippet: Read ArcGIS Offline Geodatabase into ArcGIS Runtime in WPF
Here is an quick code snippet for loading ArcGIS runtime database ( offline database) in .NET in ESRI Runtime version 100. The OverlayFeatureLayers() reads the layers from runtime geodatabase and overlayes on runtime environment map in Web Mercator Projection (EPSG: 3857)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Location;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Security;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.UI;
using ReadRuntimeGeodatabase.CustomViewModelBase;
namespace ReadRuntimeGeodatabase
{
public class MapViewModel : ViewModelBase
{
public MapViewModel()
{
OverlayFeatureLayers();
}
private Map _map = new Map(SpatialReference.Create(3857));
public Map Map
{
get { return this._map; }
set
{
if (value != this._map)
{
this._map = value;
NotifyPropertyChanged("Map");
}
}
}
private async void OverlayFeatureLayers()
{
Basemap basemap = Basemap.CreateStreets();
_map.Basemap = basemap;
string gdbsPath = @"C:\RuntimeToFileGeodatabase;
DirectoryInfo dirInfo = new DirectoryInfo(gdbsPath);
String[] files = dirInfo.GetFiles("*.geodatabase").Select(file => file.FullName).ToArray<string>();
foreach (var gdbFile in files)
{
// open a geodatabase on the local device
var gdb = await Esri.ArcGISRuntime.Data.Geodatabase.OpenAsync(gdbFile);
// loop thru all tables in the geodatabase
foreach (var table in gdb.GeodatabaseFeatureTables.ToList())
{
table.UseAdvancedSymbology = true;
var layer = new FeatureLayer(table);
await table.LoadAsync();
if (table.LoadStatus == Esri.ArcGISRuntime.LoadStatus.Loaded && table.GeometryType.ToString() != "Unknown")
{
await layer.LoadAsync();
if (layer.Name == "River_line")
{
// Defaul renderer comes with geodatabase doesn't show up
SimpleRenderer customrenderer = new SimpleRenderer();
customrenderer.Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Windows.Media.Colors.Black, 2);
layer.Renderer = customrenderer;
Envelope envelope = layer.FullExtent;
_map.InitialViewpoint = new Viewpoint(envelope);
}
else {
if (table.GeometryType.ToString() == "Polyline")
{
SimpleRenderer customrenderer = new SimpleRenderer();
customrenderer.Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, System.Windows.Media.Colors.Green, 2);
layer.Renderer = customrenderer;
}
}
System.Diagnostics.Debug.WriteLine(layer.LoadStatus + "---" + layer.Name + "--" + layer.FullExtent + "--" + table.GeometryType + "--" + layer.IsVisibleAtScale(100) + "--" + layer.IsVisible + "--" + layer.MaxScale + "--" + layer.MinScale);
if (layer.LoadStatus == Esri.ArcGISRuntime.LoadStatus.Loaded)
{
_map.OperationalLayers.Add(layer);
}
}
else
{
System.Diagnostics.Debug.WriteLine("No Geom -->" + table.TableName);
}
}
}
}
}
}
Git SSL certificate problem: self signed certificate [Solution]
git clone https://......./data.git
throws ssl error resembling to following:
Cloning into 'data'...
fatal: unable to access 'https://*/data.git/': SSL certificate problem: self signed certificate in certifica te chain
git -c http.sslVerify=false clone https://......./data.git
throws ssl error resembling to following:
Cloning into 'data'...
fatal: unable to access 'https://*/data.git/': SSL certificate problem: self signed certificate in certifica te chain
Solution - disable sslVerify and clone it
git -c http.sslVerify=false clone https://......./data.git
Subscribe to:
Posts
(
Atom
)