public ElevationDialog(IEditorService edSvc, IVectorScaleRange2 vsr2, string featureSourceId, ClassDefinition clsDef, string provider) { InitializeComponent(); _edSvc = edSvc; _vsr2 = vsr2; _clsDef = clsDef; _provider = provider; _featureSourceId = featureSourceId; cmbUnits.DataSource = Enum.GetValues(typeof(LengthUnitType)); cmbZOffsetType.DataSource = Enum.GetValues(typeof(ElevationTypeType)); _elSettings = vsr2.ElevationSettings; grpSettings.Enabled = (_elSettings != null); chkEnabled.Checked = (_elSettings != null); if (_elSettings == null) _elSettings = vsr2.Create("0", "0", ElevationTypeType.RelativeToGround, LengthUnitType.Meters); //NOXLATE try { _init = true; txtZExtrusion.Text = _elSettings.ZExtrusion; txtZOffset.Text = _elSettings.ZOffset; cmbUnits.SelectedItem = _elSettings.Unit; cmbZOffsetType.SelectedItem = _elSettings.ZOffsetType; } finally { _init = false; } }
public ElevationDialog(IEditorService edSvc, IVectorScaleRange2 vsr2, string featureSourceId, ClassDefinition clsDef, string provider) { InitializeComponent(); _edSvc = edSvc; _vsr2 = vsr2; _clsDef = clsDef; _provider = provider; _featureSourceId = featureSourceId; cmbUnits.DataSource = Enum.GetValues(typeof(LengthUnitType)); cmbZOffsetType.DataSource = Enum.GetValues(typeof(ElevationTypeType)); _elSettings = vsr2.ElevationSettings; grpSettings.Enabled = (_elSettings != null); chkEnabled.Checked = (_elSettings != null); if (_elSettings == null) { _elSettings = vsr2.Create("0", "0", ElevationTypeType.RelativeToGround, LengthUnitType.Meters); //NOXLATE } try { _init = true; txtZExtrusion.Text = _elSettings.ZExtrusion; txtZOffset.Text = _elSettings.ZOffset; cmbUnits.SelectedItem = _elSettings.Unit; cmbZOffsetType.SelectedItem = _elSettings.ZOffsetType; } finally { _init = false; } }
/// <summary> /// Loads the specified parent. /// </summary> /// <param name="parent">The parent.</param> /// <param name="styles">The styles.</param> public void LoadStyles(IVectorScaleRange2 parent, BindingList <ICompositeTypeStyle> styles) { _parent = parent; foreach (var ctrl in _controls.Values) { ctrl.Dispose(); } _controls.Clear(); _styles = styles; lstStyles.DataSource = _styles; }
/// <summary> /// Loads the specified parent. /// </summary> /// <param name="parent">The parent.</param> /// <param name="styles">The styles.</param> public void LoadStyles(IVectorScaleRange2 parent, BindingList<ICompositeTypeStyle> styles) { _parent = parent; foreach (var ctrl in _controls.Values) { ctrl.Dispose(); } _controls.Clear(); _styles = styles; lstStyles.DataSource = _styles; }
private static void CreateTracksLayer(IServerConnection conn, string resId, string layerId) { //We use the Utility class to create our layer. You can also use ObjectFactory, but //that requires explicitly specifying the resource version. Using Utility will pick //the latest supported version ILayerDefinition ldf = Utility.CreateDefaultLayer(conn, LayerType.Vector); IVectorLayerDefinition vldf = (IVectorLayerDefinition)ldf.SubLayer; //Set feature source vldf.ResourceId = resId; //Set the feature class vldf.FeatureName = "SHP_Schema:Rail"; //Set the designated geometry vldf.Geometry = "SHPGEOM"; //Get the first vector scale range. This will have been created for us and is 0 to infinity IVectorScaleRange vsr = vldf.GetScaleRangeAt(0); //Get the line style ILineVectorStyle lstyle = vsr.LineStyle; //Get the first rule (a created one will only have one) ILineRule rule = lstyle.GetRuleAt(0); //What are we doing here? We're checking if this vector scale range is a //IVectorScaleRange2 instance. If it is, it means this layer definition //has a composite style attached, which takes precedence over point/area/line //styles. We don't want this, so this removes the composite styles if they //exist. IVectorScaleRange2 vsr2 = vsr as IVectorScaleRange2; if (vsr2 != null) { vsr2.CompositeStyle = null; } //There's only one stroke here, but iteration is the only //way to go through foreach (var stroke in rule.Strokes) { //Set color to red stroke.Color = "ffff0000"; } //Now save it conn.ResourceService.SaveResourceAs(ldf, layerId); }
/// <summary> /// Perform base validation logic /// </summary> /// <param name="context"></param> /// <param name="resource"></param> /// <param name="recurse"></param> /// <returns></returns> protected ValidationIssue[] ValidateBase(ResourceValidationContext context, IResource resource, bool recurse) { Check.ArgumentNotNull(context, nameof(context)); if (context.IsAlreadyValidated(resource.ResourceID)) { return(null); } var ldef = resource as ILayerDefinition; var vldef = ldef.SubLayer as IVectorLayerDefinition; var gldef = ldef.SubLayer as IRasterLayerDefinition; var dldef = ldef.SubLayer as IDrawingLayerDefinition; List <ValidationIssue> issues = new List <ValidationIssue>(); if (ldef.SubLayer == null) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_LayerNull, Strings.LDF_LayerNullError)); } ClassDefinition cls = null; if (vldef != null || gldef != null) { //Load referenced feature source IFeatureSource fs = null; try { fs = (IFeatureSource)context.GetResource(ldef.SubLayer.ResourceId); } catch (Exception) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_FeatureSourceLoadError, string.Format(Strings.LDF_FeatureSourceLoadError))); } if (fs != null) { //Verify specified feature class and geometry check out try { string qualClassName = vldef == null ? gldef.FeatureName : vldef.FeatureName; string geometry = vldef == null ? gldef.Geometry : vldef.Geometry; bool foundSchema = false; bool foundGeometry = false; cls = this.Connection.FeatureService.GetClassDefinition(fs.ResourceID, qualClassName); if (cls != null) { foundSchema = true; foreach (PropertyDefinition col in cls.Properties) { if (col.Name == geometry) { foundGeometry = true; break; } } if (vldef != null && vldef.PropertyMapping != null) { foreach (INameStringPair s in vldef.PropertyMapping) { bool found = false; foreach (PropertyDefinition col in cls.Properties) { if (col.Name == s.Name) { found = true; break; } } if (!found) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_InvalidPropertyMapping, string.Format(Strings.LDF_InvalidPropertyMapping, s.Name, qualClassName))); } } } } if (!foundSchema) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_ClassNotFound, string.Format(Strings.LDF_SchemaMissingError, qualClassName, fs.ResourceID))); } else if (!foundGeometry) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_GeometryNotFound, string.Format(Strings.LDF_GeometryMissingError, geometry, qualClassName, fs.ResourceID))); } } catch (Exception ex) { issues.Add(new ValidationIssue(fs, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_Generic, string.Format(Strings.LDF_SchemaAndColumnReadFailedError, ex.ToString()))); } if (recurse) { issues.AddRange(ResourceValidatorSet.Validate(context, fs, recurse)); } } } if (vldef != null) { if (string.IsNullOrEmpty(vldef.FeatureName)) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_MissingFeatureName, Strings.LDF_MissingFeatureSourceError)); } if (string.IsNullOrEmpty(vldef.Geometry)) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_MissingGeometry, Strings.LDF_MissingGeometryError)); } if (vldef.VectorScaleRange == null || !vldef.HasVectorScaleRanges()) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_MissingScaleRanges, Strings.LDF_MissingScaleRangesError)); } else { //Test for overlapping scale ranges List <KeyValuePair <double, double> > ranges = new List <KeyValuePair <double, double> >(); foreach (IVectorScaleRange vsr in vldef.VectorScaleRange) { IVectorScaleRange2 vsr2 = vsr as IVectorScaleRange2; if (vsr2 != null) { var area = vsr2.AreaStyle; var line = vsr2.LineStyle; var point = vsr2.PointStyle; if (vsr2.CompositeStyleCount > 0 && (area != null || line != null || point != null)) { issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_LayerDefinition_CompositeStyleDefinedAlongsideBasicStyle, string.Format( Strings.LDF_CompositeStyleDefinedAlongsideBasicStyle, vsr2.MinScale.HasValue ? vsr2.MinScale.Value : 0, vsr2.MaxScale.HasValue ? vsr2.MaxScale.Value.ToString() : Strings.Infinity))); } if (vsr2.CompositeStyleCount > 0) { foreach (var cs in vsr2.CompositeStyle) { foreach (var cr in cs.CompositeRule) { if (cr.CompositeSymbolization != null) { foreach (var si in cr.CompositeSymbolization.SymbolInstance) { //verify that symbol references point to valid symbol definitions if (si.Reference.Type == SymbolInstanceType.Reference) { var symRef = (ISymbolInstanceReferenceLibrary)si.Reference; if (!context.ResourceExists(symRef.ResourceId)) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_SymbolDefintionReferenceNotFound, string.Format( Strings.LDF_SymbolDefintionReferenceNotFound, symRef.ResourceId))); } if (cls != null) { //warn if the symbol definition has usage contexts that are irrelevant against the layer's feature source var prop = cls.FindProperty(vldef.Geometry) as GeometricPropertyDefinition; if (prop != null) { var gtypes = new List <FeatureGeometricType>(prop.GetIndividualGeometricTypes()); var sym = context.GetResource(symRef.ResourceId) as ISimpleSymbolDefinition; if (sym != null) { if (sym.LineUsage != null && !gtypes.Contains(FeatureGeometricType.Curve)) { issues.Add(new ValidationIssue(resource, ValidationStatus.Information, ValidationStatusCode.Info_LayerDefinition_IrrelevantUsageContext, string.Format( Strings.LDF_IrrelevantUsageContext, symRef.ResourceId, FeatureGeometricType.Curve.ToString()))); } if (sym.AreaUsage != null && !gtypes.Contains(FeatureGeometricType.Surface)) { issues.Add(new ValidationIssue(resource, ValidationStatus.Information, ValidationStatusCode.Info_LayerDefinition_IrrelevantUsageContext, string.Format( Strings.LDF_IrrelevantUsageContext, symRef.ResourceId, FeatureGeometricType.Surface.ToString()))); } if (sym.PointUsage != null && !gtypes.Contains(FeatureGeometricType.Point)) { issues.Add(new ValidationIssue(resource, ValidationStatus.Information, ValidationStatusCode.Info_LayerDefinition_IrrelevantUsageContext, string.Format( Strings.LDF_IrrelevantUsageContext, symRef.ResourceId, FeatureGeometricType.Point.ToString()))); } } } } } //verify that the overrides specified are for symbol parameters that actually exist if (si.ParameterOverrides.Count > 0) { if (si.Reference.Type == SymbolInstanceType.Reference) { var symRef = (ISymbolInstanceReferenceLibrary)si.Reference; var sym = (ISymbolDefinitionBase)context.GetResource(symRef.ResourceId); var paramList = new Dictionary <string, IParameter>(); foreach (var p in sym.GetParameters()) { paramList[p.Identifier] = p; } foreach (var ov in si.ParameterOverrides.Override) { if (!paramList.ContainsKey(ov.ParameterIdentifier)) { issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_LayerDefinition_SymbolParameterOverrideToNonExistentParameter, string.Format( Strings.LDF_SymbolParameterOverrideToNonExistentParameter, symRef.ResourceId, ov.ParameterIdentifier))); } } } } } } } } } } ranges.Add(new KeyValuePair <double, double>( vsr.MaxScale.HasValue ? vsr.MaxScale.Value : double.PositiveInfinity, vsr.MinScale.HasValue ? vsr.MinScale.Value : double.NegativeInfinity)); } double min = double.PositiveInfinity; double max = double.NegativeInfinity; foreach (KeyValuePair <double, double> sr in ranges) { min = Math.Min(min, sr.Value); max = Math.Max(max, sr.Key); if (sr.Key < sr.Value) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_MinMaxScaleSwapped, string.Format(Strings.LDF_MinAndMaxScaleSwappedError, sr.Value, sr.Key))); } } ranges.Sort(CompareScales); //TODO: Detect gaps in scale ranges for (int i = 0; i < ranges.Count; i++) { for (int j = i + 1; j < ranges.Count; j++) { if (ranges[i].Key > ranges[j].Value || ranges[i].Value > ranges[j].Value) { issues.Add(new ValidationIssue(resource, ValidationStatus.Information, ValidationStatusCode.Info_LayerDefinition_ScaleRangeOverlap, string.Format(Strings.LDF_ScaleRangesOverlapInformation, ranges[i].Value, ranges[i].Key, ranges[j].Value, ranges[j].Key))); } } } } } else if (gldef != null) { if (string.IsNullOrEmpty(gldef.FeatureName)) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_MissingFeatureName, Strings.LDF_MissingFeatureSourceError)); } if (string.IsNullOrEmpty(gldef.Geometry)) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_MissingGeometry, Strings.LDF_MissingGeometryError)); } if (gldef.GridScaleRange == null || gldef.GridScaleRangeCount == 0) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_NoGridScaleRanges, Strings.LDF_MissingScaleRangesError)); } else if (gldef.GridScaleRangeCount != 1) { issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_LayerDefinition_MultipleGridScaleRanges, Strings.LDF_MultipleScaleRangesWarning)); } } else if (dldef != null) { IDrawingSource dws = null; try { dws = (IDrawingSource)context.GetResource(dldef.ResourceId); } catch (Exception) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_DrawingSourceError, Strings.LDF_DrawingSourceError)); } if (dws != null) { if (Array.IndexOf(this.Connection.Capabilities.SupportedServices, (int)ServiceType.Drawing) >= 0) { var dwSvc = (IDrawingService)this.Connection.GetService((int)ServiceType.Drawing); //Check if specified section exists var shtList = dwSvc.EnumerateDrawingSections(dws.ResourceID); DrawingSectionListSection sheet = null; foreach (var sht in shtList.Section) { if (sht.Name.Equals(dldef.Sheet)) { sheet = sht; break; } } if (sheet == null) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_DrawingSourceSheetNotFound, string.Format(Strings.LDF_SheetNotFound, dldef.Sheet))); } else { //null or empty filter means all layers, in that case do nothing if (!string.IsNullOrEmpty(dldef.LayerFilter)) { //Check if specified layers all exist in specified section var specifiedLayers = dldef.LayerFilter.Split(','); //NOXLATE var dwLayers = new Dictionary <string, string>(); var shtLayers = dwSvc.EnumerateDrawingLayers(dws.ResourceID, sheet.Name); foreach (var sl in shtLayers) { dwLayers.Add(sl, sl); } foreach (var sl in specifiedLayers) { if (!dwLayers.ContainsKey(sl.Trim())) { issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_LayerDefinition_DrawingSourceSheetLayerNotFound, string.Format(Strings.LDF_SheetLayerNotFound, sl.Trim(), sheet.Name))); } } } } } if (recurse) { issues.AddRange(ResourceValidatorSet.Validate(context, dws, recurse)); } } } else { issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_LayerDefinition_UnsupportedLayerType, Strings.LDF_UnsupportedLayerTypeWarning)); } context.MarkValidated(resource.ResourceID); return(issues.ToArray()); }
private void CreateDistrictsLayer(IServerConnection conn, string resId, string layerId) { //We use the Utility class to create our layer. You can also use ObjectFactory, but //that requires explicitly specifying the resource version. Using Utility will pick //the latest supported version ILayerDefinition ldf = Utility.CreateDefaultLayer(conn, LayerType.Vector); IVectorLayerDefinition vldf = (IVectorLayerDefinition)ldf.SubLayer; //Set feature source vldf.ResourceId = resId; //Set the feature class // //Note: In versions of the Sheboygan Dataset before 2.6, this used to be // // - Feature Class: SDF_2_Schema:VotingDistricts // - Identity Property: Autogenerated_SDF_ID // - Geometry Property: Data string featureClass = "Default:VotingDistricts"; string idProp = "FeatId"; string geometryProp = "Geometry"; vldf.FeatureName = featureClass; //Set the designated geometry vldf.Geometry = geometryProp; //Get the first vector scale range. This will have been created for us and is 0 to infinity IVectorScaleRange vsr = vldf.GetScaleRangeAt(0); //What are we doing here? We're checking if this vector scale range is a //IVectorScaleRange2 instance. If it is, it means this layer definition //has a composite style attached, which takes precedence over point/area/line //styles. We don't want this, so this removes the composite styles if they //exist. IVectorScaleRange2 vsr2 = vsr as IVectorScaleRange2; if (vsr2 != null) { vsr2.CompositeStyle = null; } //Get the area style IAreaVectorStyle astyle = vsr.AreaStyle; //Remove the default rule astyle.RemoveAllRules(); IFeatureService featSvc = conn.FeatureService; //Generate a random color for each distinct feature id //Perform a distinct value query IReader valueReader = featSvc.AggregateQueryFeatureSource(resId, featureClass, null, new NameValueCollection() { { "Value", "UNIQUE(" + idProp + ")" } //UNIQUE() is the aggregate function that collects all distinct values of FeatId }); while (valueReader.ReadNext()) { //The parent Layer Definition provides all the methods needed to create the necessary child elements IAreaRule rule = ldf.CreateDefaultAreaRule(); //Set the filter for this rule rule.Filter = idProp + " = " + valueReader["Value"].ToString(); //IReader allows object access by name in case you don't care to determine the data type rule.LegendLabel = valueReader["Value"].ToString(); //Assign a random color fill rule.AreaSymbolization2D.Fill.ForegroundColor = Utility.SerializeHTMLColor(RandomColor(), true); //Add this rule astyle.AddRule(rule); } valueReader.Close(); //Now save it conn.ResourceService.SaveResourceAs(ldf, layerId); }