/// <summary> /// Obtains the ID object that corresponds to the supplied formatted key. /// </summary> /// <param name="keystr">The formatted key obtained during the import</param> /// <returns>The ID corresponding to the supplied key (null if the supplied key is null /// or blank)</returns> ForeignId GetFeatureId(string keystr) { if (String.IsNullOrEmpty(keystr)) { return(null); } // First check the current map model to see if the supplied key matches a // previously created ID CadastralMapModel mapModel = CadastralMapModel.Current; ForeignId result = mapModel.FindForeignId(keystr); if (result != null) { return(result); } // Check the index of keys that have been created during this import (they // won't be added to the map model until the loading phase has been completed). if (m_KeyIndex.TryGetValue(keystr, out result)) { return(result); } // Remember a new foreign key as part of this import (it will be added to the model // after the loading phase has been completed) result = new ForeignId(keystr); m_KeyIndex.Add(keystr, result); return(result); }
/// <summary> /// Reads a user-perceived feature ID using the specified naming tags. /// </summary> /// <param name="nativeField">The tag to use for a native ID.</param> /// <param name="foreignField">The tag to use for a foreign ID.</param> /// <returns>The user-perceived ID that was read (may be null)</returns> internal FeatureId ReadFeatureId(DataField nativeField, DataField foreignField) { if (IsNextField(nativeField)) { uint nativeKey = m_Reader.ReadUInt32(nativeField.ToString()); NativeId nid = MapModel.FindNativeId(nativeKey); if (nid == null) { return(MapModel.AddNativeId(nativeKey)); } else { return(nid); } } if (IsNextField(foreignField)) { string key = m_Reader.ReadString(foreignField.ToString()); ForeignId fid = MapModel.FindForeignId(key); if (fid == null) { return(MapModel.AddForeignId(key)); } else { return(fid); } } return(null); }
private Feature ImportSymbol(Ntx.Symbol symbol, Operation creator) { IEntity what = GetEntityType(symbol, SpatialType.Point); // Get the position Ntx.Position pos = symbol.Position; PointGeometry g = new PointGeometry(pos.Easting, pos.Northing); // Ignore positions at 0,0! if (g.Easting.Microns == 0 && g.Northing.Microns == 0) { return(null); } InternalIdValue id = CadastralMapModel.Current.WorkingSession.AllocateNextId(); PointFeature p = new PointFeature(creator, id, what, g); /* * * static LOGICAL warned=FALSE; // debug * * // Get pointer to the map theme * CeTheme theme(Symbol.GetTheme()); * const CeTheme* const pTheme = theme.AddTheme(); * * // Get pointer to the entity * CeEntity* pEntity = AddEntity(Symbol.GetpFeatureCode(),pTheme,VERTEX); * * // Get the position * const CxPosition& pos = Symbol.GetPosition(); * * // For the time being ... * if ( !warned && pos.Is3D() ) { * AfxMessageBox("Elevation data is being stripped."); * warned = TRUE; * } * * // Add the position of the symbol. * CeVertex vtx(pos.GetEasting(),pos.GetNorthing()) ; * const CeLocation* pLoc = pMap->AddLocation(vtx); * * // If the location does not already have an associated point * // feature, add one now (the location may have been previously * // added via the import of a line). * * // Note that this version of AddPoint will always add a duplicate * // point at the specified location. * * CePoint* pPoint = pMap->AddPoint((CeLocation* const)pLoc,pEntity); */ // Define foreign ID (if any) ... string keystr = symbol.Key; ForeignId fid = GetFeatureId(keystr); if (fid != null) { fid.Add(p); } return(p); }
private Feature ImportName(Ntx.Name name, Operation creator) { /* * // Get pointer to the applicable map theme * CeTheme theme(Name.GetTheme()); * CeTheme* pTheme = theme.AddTheme(); * * // Get pointer to the entity type. * GRAPHICSTYPE geom = ANNOTATION; * if ( Name.IsLabel() ) geom = POLYGON; * CeEntity* pEntity = AddEntity(Name.GetpFeatureCode(),pTheme,geom); */ IEntity entity = GetEntityType(name, SpatialType.Text); // Get the text string string text = name.Text; // Get the position of the centre of the 1st character Ntx.Position pos = name.Position(0); IPosition vcentre = new Position(pos.Easting, pos.Northing); // Get text metrics float height = name.Height; float spacing = name.Spacing; float rotation = name.Rotation; // Calculate the top left corner of the first character using // the text metrics we just got ... // Get the width of the first character. For names that contain // only one character, the spacing we have will be zero, so in // that case, deduce the width of the character via the covering // rectangle. float charwidth = spacing; if (charwidth < Constants.TINY) { // Get the covering rectangle. Ntx.Position nw = name.NorthWest; Ntx.Position se = name.SouthEast; // And get the dimensions. double dx = se.Easting - nw.Easting; double dy = nw.Northing - se.Northing; // If the cover is screwed up, assume the width is 80% of the text height. if (dy < Constants.TINY) { charwidth = (float)(height * 0.8); } else { charwidth = (float)(height * (dx / dy)); } } // Define the bearing from bottom to top of the text. double vbear = (double)rotation; // Get position directly above the centre of the 1st char. IPosition above = Geom.Polar(vcentre, vbear, 0.5 * (double)height); // Define the bearing from the point we just got to the // start of the text string. double hbear = vbear - Constants.PIDIV2; // Back up half a character to get the initial corner. PointGeometry topleft = new PointGeometry(Geom.Polar(above, hbear, 0.5 * (double)charwidth)); IFont font = null; double width = (double)text.Length * charwidth; TextFeature result = null; if (name.IsLabel) { // Create key text string keystr = name.Text; KeyTextGeometry kt = new KeyTextGeometry(topleft, font, height, width, rotation); InternalIdValue id = CadastralMapModel.Current.WorkingSession.AllocateNextId(); result = new TextFeature(creator, id, entity, kt); kt.Label = result; result.SetTopology(true); // Define the label's foreign ID and form a two-way association ForeignId fid = GetFeatureId(keystr); Debug.Assert(fid != null); fid.Add(result); // Remember the reference position of the label. Ntx.Position xp = name.RefPosition; IPointGeometry pp = new PointGeometry(xp.Easting, xp.Northing); result.SetPolPosition(pp); } else { // Create a miscellaneous text label. MiscTextGeometry mt = new MiscTextGeometry(text, topleft, font, height, width, rotation); InternalIdValue id = CadastralMapModel.Current.WorkingSession.AllocateNextId(); result = new TextFeature(creator, id, entity, mt); result.SetTopology(false); } return(result); }
/// <summary> /// Obtains the ID object that corresponds to the supplied formatted key. /// </summary> /// <param name="keystr">The formatted key obtained during the import</param> /// <returns>The ID corresponding to the supplied key (null if the supplied key is null /// or blank)</returns> ForeignId GetFeatureId(string keystr) { if (String.IsNullOrEmpty(keystr)) return null; // First check the current map model to see if the supplied key matches a // previously created ID CadastralMapModel mapModel = CadastralMapModel.Current; ForeignId result = mapModel.FindForeignId(keystr); if (result != null) return result; // Check the index of keys that have been created during this import (they // won't be added to the map model until the loading phase has been completed). if (m_KeyIndex.TryGetValue(keystr, out result)) return result; // Remember a new foreign key as part of this import (it will be added to the model // after the loading phase has been completed) result = new ForeignId(keystr); m_KeyIndex.Add(keystr, result); return result; }