public static bool RenameDuplicatedNames(mapObj map) { bool hasDuplicate = false; for (int i = 0; i < map.numlayers; i++) { layerObj layer = map.getLayer(i); if (layer.name == "__embed__scalebar" || layer.name == "__embed__legend") { continue; } string originalName = layer.name; if (originalName == null) { originalName = "layer"; } layer.name = null; string versionedName = GetUniqueLayerName(map, originalName, 0); layer.name = originalName; if (originalName.Trim() != versionedName) { hasDuplicate = true; layer.name = versionedName; } } return(hasDuplicate); }
/// <summary> /// Update the list item according to a modified style /// </summary> /// <param name="index">the index of the lit item</param> /// <param name="style">the style object</param> private void UpdateStyleInList(int index) { layerObj layer; if (target.GetParent().GetType() == typeof(scalebarObj)) { layer = new layerObj(null); } else { layer = target.GetParent().GetParent(); } ListViewItem item = listViewStyles.Items[index]; styleObj style = (styleObj)item.Tag; classObj styleclass = new classObj(null); styleclass.insertStyle(style, -1); // creating the list icon using (classObj def_class = new classObj(null)) // for drawing legend images { using (imageObj image2 = def_class.createLegendIcon(map, layer, 30, 20)) { MS_LAYER_TYPE type = layer.type; try { // modify the layer type in certain cases for drawing correct images string geomtransform = style.getGeomTransform().ToLower(); if (geomtransform != null) { if (geomtransform.Contains("labelpoly")) { layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON; } else if (geomtransform.Contains("labelpnt")) { layer.type = MS_LAYER_TYPE.MS_LAYER_POINT; } } styleclass.drawLegendIcon(map, layer, 20, 10, image2, 5, 5); } finally { layer.type = type; } byte[] img = image2.getBytes(); using (MemoryStream ms = new MemoryStream(img)) { imageList.Images[item.ImageIndex] = Image.FromStream(ms); } item.SubItems[1].Text = style.size.ToString(); item.SubItems[2].Text = style.width.ToString(); item.SubItems[3].Text = style.symbolname; } } }
private void goToLayerTextToolStripMenuItem_Click(object sender, EventArgs e) { if (listView.SelectedItems.Count > 0 && GoToLayerText != null) { layerObj layer = (layerObj)listView.SelectedItems[0].SubItems[0].Tag; GoToLayerText(this, layer, -1); } }
/// <summary> /// Returns the next name of a class to be added to the layer /// </summary> /// <param name="layer">The layer referece</param> /// <returns>The class name</returns> public static string GetClassName(layerObj layer) { if (layer == null) { return(""); } return("Class (" + Convert.ToString(layer.numclasses - 1) + ")"); }
private void goToClassTextToolStripMenuItem_Click(object sender, EventArgs e) { if (listView.SelectedItems.Count > 0 && GoToLayerText != null) { layerObj layer = (layerObj)listView.SelectedItems[0].SubItems[0].Tag; shapeObj shape = (shapeObj)listView.SelectedItems[0].SubItems[1].Tag; GoToLayerText(this, layer, shape.classindex); } }
/// <summary> /// Updating the enabled state of the controls /// </summary> private void UpdateControlState() { buttonEditStyle.Enabled = buttonRemoveStyle.Enabled = listViewStyles.SelectedIndices.Count > 0; buttonMoveStyleUp.Enabled = buttonMoveStyleDown.Enabled = listViewStyles.SelectedIndices.Count > 0; labelBindingControllerAngle.Enabled = textBoxAngle.Enabled = (MS_POSITIONS_ENUM)comboBoxAngleMode.SelectedItem == MS_POSITIONS_ENUM.MS_NONE; layerObj layer = null; if (target.GetParent().GetParent().GetType() == typeof(layerObj)) { layer = target.GetParent().GetParent(); } if (layer != null) { checkBoxForce.Enabled = false; checkBoxAutoMinFeatureSize.Enabled = false; textBoxMinFeatureSize.Enabled = false; textBoxPriority.Enabled = false; labelBindingControllerPriority.Enabled = false; textBoxBuffer.Enabled = false; textBoxMinSize.Enabled = false; textBoxMaxSize.Enabled = false; if (layer.labelcache == mapscript.MS_ON) { checkBoxForce.Enabled = true; checkBoxAutoMinFeatureSize.Enabled = true; textBoxMinFeatureSize.Enabled = true; textBoxPriority.Enabled = true; labelBindingControllerPriority.Enabled = true; textBoxBuffer.Enabled = true; } if (layer.symbolscaledenom > 0) { textBoxMinSize.Enabled = true; textBoxMaxSize.Enabled = true; } buttonMoveStyleUp.Enabled = false; buttonMoveStyleDown.Enabled = false; buttonEditStyle.Enabled = false; if (listViewStyles.SelectedIndices.Count > 0) { buttonEditStyle.Enabled = true; if (listViewStyles.SelectedIndices[0] > 0) { buttonMoveStyleUp.Enabled = true; } if (listViewStyles.SelectedIndices[0] < listViewStyles.Items.Count - 1) { buttonMoveStyleDown.Enabled = true; } } } }
public void testGetLayerObjByName() { mapObj map = new mapObj(mapfile); layerObj newLayer = map.getLayerByName("POLYGON"); map = null; gc(); assertNotNull(newLayer.map, "testGetLayerObjByName"); assert(newLayer.refcount == 2, "testGetLayerObjByName refcount"); }
public void testGetLayerObj() { mapObj map = new mapObj(mapfile); layerObj newLayer = map.getLayer(1); map = null; gc(); assertNotNull(newLayer.map, "testGetLayerObj"); assert(newLayer.refcount == 2, "testGetLayerObj refcount"); }
/// <summary> /// Create a new classObj with random color setting added to the parent layer. /// </summary> /// <param name="layer">The parent layer object.</param> public static void CreateRandomClass(layerObj layer) { using (classObj newclass = new classObj(layer)) { newclass.name = GetClassName(layer); newclass.template = "query.html"; styleObj style = new styleObj(newclass); style.size = 8; // set default size (#4339) SetDefaultColor(layer.type, style); } }
internal static HandleRef getCPtrAndSetReference(layerObj obj, object parent) { if (obj != null) { obj.swigParentRef = parent; return obj.swigCPtr; } else { return new HandleRef(null, IntPtr.Zero); } }
//for example:use layer.clone() public SymbolSelectorDialog(layerObj layer) { InitializeComponent(); if (layer != null) { m_pCurrentLayer = layer; m_pCurrentClass = layer.getClass(0); m_pEditingClass = m_pCurrentClass.clone(); m_LayerType = layer.type; } }
public void testGetClassObj() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj newClass = layer.getClass(0); map = null; layer = null; gc(); assertNotNull(newClass.layer, "testGetClassObj"); assert(newClass.refcount == 2, "testGetClassObj refcount"); }
public void testGetStyleObj() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj classobj = layer.getClass(0); styleObj style = classobj.getStyle(0); map = null; layer = null; classobj = null; gc(); assert(style.refcount == 2, "testGetStyleObj"); }
public void testLayerObjDestroy() { mapObj map = new mapObj(mapfile); layerObj newLayer = new layerObj(map); layerObj reference = map.getLayer(map.numlayers - 1); assert(newLayer.refcount == 3, "testLayerObjDestroy precondition"); newLayer.Dispose(); // force the destruction for Mono on Windows because of the constructor overload newLayer = null; gc(); assert(reference.refcount == 2, "testLayerObjDestroy"); }
public void testRemoveLayerObj() { mapObj map = new mapObj(mapfile); layerObj newLayer = new layerObj(null); map.insertLayer(newLayer, 0); map.removeLayer(0); map = null; gc(); assert(newLayer.refcount == 1, "testRemoveLayerObj"); }
public FieldSelectionForm(layerObj layer, string msg) { InitializeComponent(); labelItem.Text = msg; layer.open(); for (int i = 0; i < layer.numitems; i++) { listBoxItems.Items.Add(layer.getItem(i)); } layer.close(); buttonOK.Enabled = false; }
public void testGetLayerObjByNameDestroy() { mapObj map = new mapObj(mapfile); layerObj newLayer = map.getLayerByName("POLYGON"); layerObj reference = map.getLayerByName("POLYGON"); assert(newLayer.refcount == 3, "testGetLayerObjByNameDestroy precondition"); //newLayer.Dispose(); // force the destruction needed for Mono on Windows newLayer = null; gc(); assert(reference.refcount == 2, "testGetLayerObjByNameDestroy"); }
internal static HandleRef getCPtrAndDisown(layerObj obj, object parent) { if (obj != null) { obj.swigCMemOwn = false; obj.swigParentRef = parent; return obj.swigCPtr; } else { return new HandleRef(null, IntPtr.Zero); } }
public void testGetClassObjDestroy() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj newClass = layer.getClass(0); classObj reference = layer.getClass(0); assert(newClass.refcount == 3, "testGetClassObjDestroy precondition"); map = null; layer = null; newClass = null; gc(); assert(reference.refcount == 2, "testGetClassObjDestroy"); }
/// <summary> /// Initialize the default settings of a newly created labelObj /// </summary> /// <param name="layer">The parent layer object.</param> public static void InitializeDefaultLabel(layerObj layer) { labelObj label; if (layer.getClass(0).numlabels == 0) { label = new labelObj(); layer.getClass(0).addLabel(label); } label = layer.getClass(0).getLabel(0); SetDefaultLabel(label, layer.map); }
public void testInsertLayerObj() { mapObj map = new mapObj(mapfile); layerObj newLayer = new layerObj(null); map.insertLayer(newLayer, -1); map = null; gc(); assertNotNull(newLayer.map, "testInsertLayerObj"); assert(newLayer.refcount == 2, "testInsertLayerObj refcount"); }
public void testRemoveClassObj() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj newClass = new classObj(null); layer.insertClass(newClass, 0); layer.removeClass(0); map = null; layer = null; gc(); assert(newClass.refcount == 1, "testRemoveClassObj"); }
public void testClassObjDestroy() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj newClass = new classObj(layer); classObj reference = layer.getClass(layer.numclasses - 1); assert(newClass.refcount == 3, "testClassObjDestroy precondition"); newClass.Dispose(); // force the destruction for Mono on Windows because of the constructor overload map = null; layer = null; newClass = null; gc(); assert(reference.refcount == 2, "testClassObjDestroy"); }
public void testGetStyleObjDestroy() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj classobj = layer.getClass(0); styleObj style = classobj.getStyle(0); styleObj reference = classobj.getStyle(0); assert(style.refcount == 3, "testGetStyleObjDestroy precondition"); map = null; layer = null; classobj = null; style = null; gc(); assert(reference.refcount == 2, "testGetStyleObjDestroy"); }
/// <summary> /// Check whether this layer has a metadata tag /// </summary> /// <param name="layer">The layer object</param> /// <param name="key_to_find">the metadata key to search for</param> /// <returns></returns> public static bool HasMetadata(layerObj layer, string key_to_find) { string key = layer.getFirstMetaDataKey(); while (key != null) { if (key == key_to_find) { return(true); } key = layer.getNextMetaDataKey(key); } return(false); }
/// <summary> /// Find a metadata tag /// </summary> /// <param name="layer">The layer object</param> /// <param name="key_to_find">the metadata key to search for</param> /// <returns></returns> public static string FindMetadata(layerObj layer, string key_to_find) { string key = layer.getFirstMetaDataKey(); while (key != null) { if (key.StartsWith(key_to_find)) { return(key); } key = layer.getNextMetaDataKey(key); } return(null); }
public void testRemoveStyleObj() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj classobj = layer.getClass(0); styleObj newStyle = new styleObj(null); classobj.insertStyle(newStyle, 0); classobj.removeStyle(0); map = null; layer = null; classobj = null; gc(); assert(newStyle.refcount == 1, "testRemoveStyleObj"); }
public void testInsertStyleObj() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj classobj = layer.getClass(0); styleObj newStyle = new styleObj(null); classobj.insertStyle(newStyle, -1); assert(newStyle.refcount == 2, "testInsertStyleObj precondition"); map = null; layer = null; classobj = null; gc(); assert(newStyle.refcount == 2, "testInsertStyleObj"); }
public void testInsertClassObj() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj newClass = new classObj(null); layer.insertClass(newClass, -1); assertNotNull(newClass.layer, "testInsertClassObj precondition"); map = null; layer = null; gc(); assertNotNull(newClass.layer, "testInsertClassObj"); assert(newClass.refcount == 2, "testInsertClassObj refcount"); }
public void testStyleObjDestroy() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj classobj = layer.getClass(0); styleObj newStyle = new styleObj(classobj); styleObj reference = classobj.getStyle(classobj.numstyles - 1); assert(newStyle.refcount == 3, "testStyleObjDestroy"); newStyle.Dispose(); // force the destruction for Mono on Windows because of the constructor overload map = null; layer = null; classobj = null; newStyle = null; gc(); assert(reference.refcount == 2, "testStyleObjDestroy"); }
/// <summary> /// Append a value to an existing metadata or create a new tag if that doesn't exist /// </summary> /// <param name="layer">The layer object</param> /// <param name="key">The metadata key</param> /// <param name="value">The value to append</param> /// <param name="value">The separator to be used when appending</param> public static void AppendMetadata(layerObj layer, string key_to_find, string value, string separator) { string key = layer.getFirstMetaDataKey(); while (key != null) { if (key == key_to_find) { layer.setMetaData(key_to_find, layer.getMetaData(key_to_find) + separator + value); return; } key = layer.getNextMetaDataKey(key); } layer.setMetaData(key_to_find, value); }
private static bool IsLayerQueryable(layerObj layer) { if ( layer.type == MS_LAYER_TYPE.MS_LAYER_TILEINDEX ) return false; if(layer.template != null && layer.template.Length > 0) return true; for(int i=0; i<layer.numclasses; i++) { if(layer.getClass(i).template != null && layer.getClass(i).template.Length > 0) return true; } return false; }
private ListViewItem AddListItem(styleObj classStyle, layerObj layer, string name) { ListViewItem item = null; classObj styleclass = new classObj(null); styleclass.insertStyle(classStyle, -1); mapObj map2 = map; if (layer.map != null) { map2 = layer.map; } // creating the listicons using (classObj def_class = new classObj(null)) // for drawing legend images { using (imageObj image2 = def_class.createLegendIcon( map2, layer, imageList.ImageSize.Width, imageList.ImageSize.Height)) { MS_LAYER_TYPE type = layer.type; try { //SETPH: actually we should not modify the type of the style(point line polygon) for the style category list, only for the preview //// modify the layer type in certain cases for drawing correct images //if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly")) //layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON; //else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt")) //layer.type = MS_LAYER_TYPE.MS_LAYER_POINT; styleclass.drawLegendIcon(map2, layer, 44, 44, image2, 2, 2); } finally { layer.type = type; } byte[] img = image2.getBytes(); using (MemoryStream ms = new MemoryStream(img)) { imageList.Images.Add(Image.FromStream(ms)); } // add new item item = new ListViewItem(name, imageList.Images.Count - 1); item.ToolTipText = name; item.Tag = classStyle; listView.Items.Add(item); } } return(item); }
public static void TestMSSQLConnection(string connection, string data) { mapObj samplemap = new mapObj(null); layerObj samplelayer = new layerObj(samplemap); samplelayer.connectiontype = MS_CONNECTION_TYPE.MS_PLUGIN; samplelayer.plugin_library = samplelayer.plugin_library_original = "msplugin_mssql2008.dll"; samplelayer.connection = connection; samplelayer.data = data; try { samplelayer.open(); } finally { samplelayer.close(); } }
public void testRemoveLayerObj() { mapObj map=new mapObj(mapfile); layerObj newLayer=new layerObj(null); map.insertLayer(newLayer,0); map.removeLayer(0); map=null; gc(); assert(newLayer.refcount == 1, "testRemoveLayerObj"); }
public void testInsertLayerObj() { mapObj map=new mapObj(mapfile); layerObj newLayer=new layerObj(null); map.insertLayer(newLayer,-1); map=null; gc(); assertNotNull(newLayer.map, "testInsertLayerObj"); assert(newLayer.refcount == 2, "testInsertLayerObj refcount"); }
public void testInsertLayerObjDestroy() { mapObj map=new mapObj(mapfile); layerObj newLayer=new layerObj(null); map.insertLayer(newLayer,0); layerObj reference = map.getLayer(0); assert(newLayer.refcount == 3, "testInsertLayerObjDestroy precondition"); newLayer.Dispose(); // force the destruction for Mono on Windows because of the constructor overload newLayer=null; gc(); assert(reference.refcount == 2, "testInsertLayerObjDestroy"); }
private void AddLayerNode(layerObj layer, TreeNode layersnode,int index) { if ((layer == null) || (layersnode == null)) return; TreeNode layerNode = new TreeNode(); layerNode.Text = layer.name; if (layer.status == 0) { layerNode.ImageIndex = IMAGEINDEX_LAYER_OFF; layerNode.SelectedImageIndex = IMAGEINDEX_LAYER_OFF; } else { if (layer.isVisible() != 0) { layerNode.ImageIndex = IMAGEINDEX_LAYER_ON; layerNode.SelectedImageIndex = IMAGEINDEX_LAYER_ON; } else { layerNode.ImageIndex = IMAGEINDEX_LAYER_LOCK; layerNode.SelectedImageIndex = IMAGEINDEX_LAYER_LOCK; } } if ((index > 0) && (index < layersnode.Nodes.Count - 1)) layersnode.Nodes.Insert(index, layerNode); else layersnode.Nodes.Add(layerNode); AddLayerClassNode(layer, layerNode); }
//�����������Ч����¥�ϵ�1/50������ //public static string GetAbsolutePath(string dir, string path) //{ //string strDir = Directory.GetCurrentDirectory(); //Directory.SetCurrentDirectory(dir); //string strNew = Path.GetFullPath(path); //Directory.SetCurrentDirectory(strDir); //return strNew; //} /// <summary> /// get all fields' name of the layer /// </summary> /// <param name="layer"></param> /// <returns></returns> public static StringCollection GetFieldsOfLayer(layerObj layer) { StringCollection pStringCollection = new StringCollection(); string strDataPath = GetAbsolutePathOfData(layer); IWorkspaceFactory pWsf = new ShapefileWorkspaceFactory(); IWorkspace pWs = pWsf.OpenFromFile(Path.GetDirectoryName(strDataPath), 0); if (pWs != null) { IFeatureWorkspace pFws = pWs as IFeatureWorkspace; string strDataName = Path.GetFileNameWithoutExtension(strDataPath); IFeatureClass pFeatureClass = pFws.OpenFeatureClass(strDataName); if (pFeatureClass != null) { IFields pFields = pFeatureClass.Fields; if(pFields != null) { int iCount = pFields.FiledCount; for (int i = 0; i < iCount; i++) { pStringCollection.Add(pFields.GetField(i).Name); } } } } return pStringCollection; }
public int insertLayer(layerObj layer, int index) { int ret = mapscriptPINVOKE.mapObj_insertLayer(swigCPtr, layerObj.getCPtrAndSetReference(layer, ThisOwn_false()), index); if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve(); return ret; }
private void AddLayerClassNode(layerObj layer, TreeNode layernode) { if ((layer == null) || (layernode == null)) return; int iClassCount = layer.numclasses; for (int i = 0; i < iClassCount; i++) { classObj pClass = layer.getClass(i); imageObj pSymbolImage = pClass.createLegendIcon(m_pMap, layer, 16, 16); byte[] buffer = pSymbolImage.getBytes(); System.IO.MemoryStream ms = new System.IO.MemoryStream(); ms.Write(buffer, 0, buffer.Length); imageListLeg.Images.Add(Image.FromStream(ms)); ms.Dispose(); pSymbolImage.Dispose(); int iIndex = imageListLeg.Images.Count - 1; TreeNode subNode2 = new TreeNode("", iIndex, iIndex); layernode.Nodes.Add(subNode2); } }
public int draw(mapObj map, layerObj layer, imageObj image) { int ret = mapscriptPINVOKE.shapeObj_draw(swigCPtr, mapObj.getCPtr(map), layerObj.getCPtr(layer), imageObj.getCPtr(image)); if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve(); return ret; }
/// <summary> /// set the object of the page /// </summary> /// <param name="inObject"></param> public void SetObjects(object inObject) { if (inObject is layerObj) m_pLayer = inObject as layerObj; }
private void AddLayerNode(layerObj layer, TreeNode layersnode) { AddLayerNode(layer, layersnode, layersnode.Nodes.Count - 1); }
/// <summary> /// Create the theme according to the individual values of the layer contents /// </summary> private MapObjectHolder CreateLayerTheme() { if (layer == null) return null; int index; for (index = 0; index < fieldName.Length; index++) { if (fieldName[index] == comboBoxColumns.Text) break; } if (index == fieldName.Length) return null; NumberFormatInfo ni = new NumberFormatInfo(); ni.NumberDecimalSeparator = "."; mapObj map = target.GetParent(); // create a new map object mapObj newMap = new mapObj(null); newMap.units = MS_UNITS.MS_PIXELS; map.selectOutputFormat(map.imagetype); // copy symbolset for (int s = 1; s < map.symbolset.numsymbols; s++) { symbolObj origsym = map.symbolset.getSymbol(s); newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym)); } // copy the fontset string key = null; while ((key = map.fontset.fonts.nextKey(key)) != null) newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, "")); newLayer = new layerObj(newMap); newLayer.type = layer.type; newLayer.status = mapscript.MS_ON; newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE; // add the classObj and styles classObj classobj; if (checkBoxKeepStyles.Checked) { classobj = layer.getClass(0).clone(); classobj.setExpression(""); // remove expression to have the class shown // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); for (int l = 0; l < classobj.numlabels; l++) LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); newLayer.insertClass(classobj, -1); } else { classobj = new classObj(newLayer); classobj.name = MapUtils.GetClassName(newLayer); styleObj style = new styleObj(classobj); style.size = 8; // set default size (#4339) if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT) { // initialize with the default marker if specified in the symbol file for point symbols symbolObj symbol; for (int s = 0; s < map.symbolset.numsymbols; s++) { symbol = map.symbolset.getSymbol(s); if (symbol.name == "default-marker") { style.symbol = s; style.symbolname = "default-marker"; break; } } } MapUtils.SetDefaultColor(layer.type, style); } // calculate breaks int classes = (int)numericUpDownClasses.Value; double[] breaks = null; if (comboBoxMode.SelectedIndex == 0) breaks = CalculateEqualInterval(classes, index); if (breaks == null) return null; for (int i = 0; i < classes; i++) { double percent = ((double)(i + 1)) / classes * 100; // creating the corresponding class object if (i > 0) { classobj = classobj.clone(); // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); for (int l = 0; l < classobj.numlabels; l++) LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); newLayer.insertClass(classobj, -1); } classobj.name = breaks[i].ToString(ni) + " - " + breaks[i + 1].ToString(ni); classobj.setExpression("(([" + comboBoxColumns.SelectedItem + "] >= " + breaks[i].ToString(ni) + ") && ([" + comboBoxColumns.SelectedItem + "] <= " + breaks[i+1].ToString(ni) + "))"); for (int j = 0; j < classobj.numstyles; j++) { styleObj style = classobj.getStyle(j); style.color = colorRampPickerColor.GetMapColorAtValue(percent); style.outlinecolor = colorRampPickerOutlineColor.GetMapColorAtValue(percent); style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent); if (checkBoxFirstOnly.Checked) break; } } return new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null)); }
private static void BuildQuery(layerObj layer, string qstring) { if (layer != null && layer.map != null) { /*layer.open(); string qs = ""; string att = ""; for (int i=0; i < layer.numitems; i++) { if (qs == "") { qs = "("; att = layer.getItem(i); } else { qs += " OR "; } qs += "'[" + layer.getItem(i) + "]'='" + qstring + "'"; } qs += ")"; layer.close();*/ string qs = qstring; string att = null; Console.WriteLine("Query string: " + qs); try { layer.queryByAttributes(layer.map, att, qs, 1); } catch (Exception e) { Console.WriteLine("BuildQuery: " + e.Message); } } }
public static void Main(string[] args) { if (args.Length < 2) usage(); // creating a new map from scratch mapObj map = new mapObj(null); // adding a layer layerObj layer = new layerObj(map); layer.type = MS_LAYER_TYPE.MS_LAYER_POINT; layer.status = mapscript.MS_ON; layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE; // define the attribute names from the inline layer layer.addProcessing("ITEMS=attribute1,attribute2,attribute3"); // define the class classObj classobj = new classObj(layer); classobj.template = "query"; // making the layer queryable // setting up the text based on multiple attributes classobj.setText("('Shape:' + '[attribute1]' + ' Color:' + '[attribute2]' + ' Size:' + '[attribute3]')"); // define the label classobj.label.outlinecolor = new colorObj(255, 255, 255, 0); classobj.label.force = mapscript.MS_TRUE; classobj.label.size = (double)MS_BITMAP_FONT_SIZES.MS_MEDIUM; classobj.label.position = (int)MS_POSITIONS_ENUM.MS_LC; classobj.label.wrap = ' '; // set up attribute binding classobj.label.setBinding((int)MS_LABEL_BINDING_ENUM.MS_LABEL_BINDING_COLOR, "attribute2"); // define the style styleObj style = new styleObj(classobj); style.color = new colorObj(0, 255, 255, 0); style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_COLOR, "attribute2"); style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_SIZE, "attribute3"); Random rand = new Random((int)DateTime.Now.ToFileTime()); ; // creating the shapes for (int i = 0; i < 10; i++) { shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT); // setting the shape attributes shape.initValues(4); shape.setValue(0, Convert.ToString(i)); shape.setValue(1, new colorObj(rand.Next(255), rand.Next(255), rand.Next(255), 0).toHex()); shape.setValue(2, Convert.ToString(rand.Next(25) + 5)); lineObj line = new lineObj(); line.add(new pointObj(rand.Next(400) + 25, rand.Next(400) + 25, 0, 0)); shape.add(line); layer.addFeature(shape); } map.width = 500; map.height = 500; map.setExtent(0,0,450,450); map.selectOutputFormat(args[0]); imageObj image = map.draw(); image.save(args[1], map); //perform a query layer.queryByRect(map, new rectObj(0, 0, 450, 450, 0)); resultObj res; shapeObj feature; using (resultCacheObj results = layer.getResults()) { if (results != null && results.numresults > 0) { // extracting the features found layer.open(); for (int j = 0; j < results.numresults; j++) { res = results.getResult(j); feature = layer.getShape(res); if (feature != null) { Console.WriteLine(" Feature: shapeindex=" + res.shapeindex + " tileindex=" + res.tileindex); for (int k = 0; k < layer.numitems; k++) { Console.Write(" " + layer.getItem(k)); Console.Write(" = "); Console.Write(feature.getValue(k)); Console.WriteLine(); } } } layer.close(); } } }
public static string GetAbsolutePathOfData(layerObj layer) { if (layer == null) return ""; //if the shapepath exist,combine the shapepath and data if (Path.IsPathRooted(layer.data)) return layer.data; else { //�ж��Ƿ����shapepath·�� if (Path.IsPathRooted(layer.map.shapepath)) return Path.Combine(layer.map.shapepath, layer.data); else { string strPath = Utility.GetAbsolutePath(layer.map.mappath, layer.map.shapepath); if (Directory.Exists(strPath)) return Path.Combine(strPath, layer.data); else return layer.data; } } }
public NewClassForm(layerObj layer,IEnumerator uniqueEnum) { InitializeComponent(); m_pCurrentLayer = layer; m_pUniqueValues = uniqueEnum; }
public MetadataForm(layerObj inLayer) { InitializeComponent(); m_curLayer = inLayer; m_LayerMeta = true; }
public FormSymbolSet(layerObj inLayer) { InitializeComponent(); m_curLayer = inLayer; }
/// <summary> /// Adding a preview feature to the layer according to the layer type. This method is used to initialize the preview controls. /// </summary> /// <param name="srcLayer">The source layer the felature should be created in.</param> /// <param name="numvalues">The number of the feature attributes to be created.</param> private void AddSampleFeature(layerObj srcLayer, int numvalues) { if (srcLayer.type == MS_LAYER_TYPE.MS_LAYER_LINE) { using (shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_LINE)) { // adding a horizontal line sample using (lineObj line = new lineObj()) { using (pointObj point = new pointObj(this.gap, this.Height / 2, 0, 0)) { line.add(point); point.setXY(this.Width - this.gap, this.Height / 2, 0); line.add(point); } shape.add(line); } if (numvalues > 0) shape.initValues(numvalues); srcLayer.addFeature(shape); } } else if (srcLayer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON) { using (shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POLYGON)) { // adding a rectangle sample using (lineObj line = new lineObj()) { using (pointObj point = new pointObj(this.gap, this.gap, 0, 0)) { line.add(point); point.setXY(this.Width - this.gap, this.gap, 0); line.add(point); point.setXY(this.Width - this.gap, this.Height - this.gap, 0); line.add(point); point.setXY(this.gap, this.Height - this.gap, 0); line.add(point); point.setXY(this.gap, this.gap, 0); line.add(point); } shape.add(line); } if (numvalues > 0) shape.initValues(numvalues); srcLayer.addFeature(shape); } } else { using (shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT)) { // adding a point sample using (lineObj line = new lineObj()) { using (pointObj point = new pointObj(this.Width / 2, this.Height / 2, 0, 0)) { line.add(point); } shape.add(line); } if (numvalues > 0) shape.initValues(numvalues); srcLayer.addFeature(shape); } } }
/// <summary> /// Adding the selected layer to map /// </summary> void AddLayerToMap() { // trying to open the layer layerObj layer = new layerObj(map); layer.connection = textBoxServer.Text.Trim(); layer.connectiontype = MS_CONNECTION_TYPE.MS_WMS; layer.type = MS_LAYER_TYPE.MS_LAYER_RASTER; layer.status = mapscript.MS_ON; // set up authentication NetworkCredential cred = (NetworkCredential)resolver.GetCredentials(); if (cred != null) { layer.metadata.set("wms_auth_username", cred.UserName); layer.metadata.set("wms_auth_password", cred.Password); layer.metadata.set("wms_auth_type", "any"); } WebProxy proxy = (WebProxy)resolver.Proxy; if (proxy != null) { layer.metadata.set("wms_proxy_host", proxy.Address.Host); layer.metadata.set("wms_proxy_port", proxy.Address.Port.ToString()); layer.metadata.set("wms_proxy_auth_type", "any"); layer.metadata.set("wms_proxy_type", resolver.ProxyType); cred = (NetworkCredential)resolver.GetProxyCredentials(); if (cred != null) { layer.metadata.set("wms_proxy_username", cred.UserName); layer.metadata.set("wms_proxy_password", cred.Password); } } // setting up the selected layer selected = new MapObjectHolder(layer, target); // set queryable flag if (wms_queryable == "1") layer.template = "query.html"; // setting up the layer metadata section layer.metadata.set("wms_name", wms_name); layer.metadata.set("wms_format", comboBoxImageFormat.Text.Trim()); layer.metadata.set("wms_server_version", wms_server_version); if (!colorPickerLayerColor.Value.IsEmpty) { colorObj color = new colorObj(colorPickerLayerColor.Value.R, colorPickerLayerColor.Value.G, colorPickerLayerColor.Value.B, 0); layer.metadata.set("wms_bgcolor", "0x" + color.toHex().Substring(1)); } if (!checkBoxTransparent.Checked) layer.metadata.set("wms_transparent", "FALSE"); // wms_style if (comboBoxStyle.Text != "") layer.metadata.set("wms_style", comboBoxStyle.Text); // title if (wms_title != null) layer.name = MapUtils.GetUniqueLayerName(map, wms_title, 0); else layer.name = MapUtils.GetUniqueLayerName(map, "Layer", 0); // scale denom if (wms_maxscaledenom > 0) layer.maxscaledenom = wms_maxscaledenom; if (wms_minscaledenom > 0) layer.maxscaledenom = wms_minscaledenom; // get bbox parameters if (wms_bbox != null && map.numlayers == 1) { // this is the first layer, set the extent of the map map.setExtent(wms_bbox.minx, wms_bbox.miny, wms_bbox.maxx, wms_bbox.maxy); } // setting up the selected projection KeyValuePair<string, string> current = (KeyValuePair<string, string>)bs.Current; string wms_srs = current.Key; // mapping not EPSG systems to the EPSG variants if (string.Compare(wms_srs, "CRS:84", true) == 0) wms_srs = "EPSG:4326"; else if (string.Compare(wms_srs, "CRS:83", true) == 0) wms_srs = "EPSG:4369"; else if (string.Compare(wms_srs, "CRS:27", true) == 0) wms_srs = "EPSG:4267"; if (wms_srs.StartsWith("EPSG", StringComparison.InvariantCultureIgnoreCase)) layer.metadata.set("wms_srs", wms_srs); layer.setProjection(wms_srs); }
public LayerPropertiesDialog(layerObj inLayer) { InitializeComponent(); m_currentLayer = inLayer; }
private ListViewItem AddListItem(styleObj classStyle, layerObj layer, string name) { ListViewItem item = null; classObj styleclass = new classObj(null); styleclass.insertStyle(classStyle, -1); mapObj map2 = map; if (layer.map != null) map2 = layer.map; // creating the listicons using (classObj def_class = new classObj(null)) // for drawing legend images { using (imageObj image2 = def_class.createLegendIcon( map2, layer, imageList.ImageSize.Width, imageList.ImageSize.Height)) { MS_LAYER_TYPE type = layer.type; try { //SETPH: actually we should not modify the type of the style(point line polygon) for the style category list, only for the preview //// modify the layer type in certain cases for drawing correct images //if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly")) //layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON; //else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt")) //layer.type = MS_LAYER_TYPE.MS_LAYER_POINT; styleclass.drawLegendIcon(map2, layer, 44, 44, image2, 2, 2); } finally { layer.type = type; } byte[] img = image2.getBytes(); using (MemoryStream ms = new MemoryStream(img)) { imageList.Images.Add(Image.FromStream(ms)); } // add new item item = new ListViewItem(name, imageList.Images.Count - 1); item.ToolTipText = name; item.Tag = classStyle; listView.Items.Add(item); } } return item; }
public int draw(mapObj map, layerObj layer, imageObj image, int classindex, string text) { int ret = mapscriptPINVOKE.rectObj_draw(swigCPtr, mapObj.getCPtr(map), layerObj.getCPtr(layer), imageObj.getCPtr(image), classindex, text); if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve(); return ret; }
//���һ����ͼ�㵽mapfile public bool addLayer(string dataPath) { if (_Map == null) { if (ErrorOccured != null) ErrorOccured(null, new MSErrorEventArgs("û�д�mapfile")); return false; } layerObj pLayer = new layerObj(_Map); pLayer.status = 1; string strName = Path.GetFileNameWithoutExtension(dataPath); pLayer.name = strName; pLayer.group = strName; string strExt = Path.GetExtension(dataPath).ToLower(); //wanliyun:2009.05.06 //add the mapinfo tab format support if ((strExt == ".shp") || (strExt == ".tab")) { IFeatureClass pFc = null; if (strExt == ".shp") { IWorkspaceFactory pWsf = new ShapefileWorkspaceFactory(); IFeatureWorkspace pFws = pWsf.OpenFromFile(dataPath, 0) as IFeatureWorkspace; pFc = pFws.OpenFeatureClass(strName); pLayer.connectiontype = MS_CONNECTION_TYPE.MS_SHAPEFILE; pLayer.data = dataPath; } else if (strExt == ".tab") { IWorkspaceFactory pWsf = new OgrWorkspaceFactory(); IFeatureWorkspace pFws = pWsf.OpenFromFile(dataPath, 0) as IFeatureWorkspace; pFc = pFws.OpenFeatureClass(strName); pLayer.connectiontype = MS_CONNECTION_TYPE.MS_OGR; pLayer.connection = dataPath; } IEnvelope pEnvelope = ((IGeoDataset)pFc).Extent; if (_Map.numlayers == 1) { _Map.extent.minx = pEnvelope.XMin; _Map.extent.miny = pEnvelope.YMin; _Map.extent.maxx = pEnvelope.XMax; _Map.extent.maxy = pEnvelope.YMax; } else { //if the layer extents lager than the map extents //reset the map extents if (pEnvelope.XMin < _Map.extent.minx) _Map.extent.minx = pEnvelope.XMin; if (pEnvelope.YMin < _Map.extent.miny) _Map.extent.miny = pEnvelope.YMin; if (pEnvelope.XMax > _Map.extent.maxx) _Map.extent.maxx = pEnvelope.XMax; if (pEnvelope.YMax > _Map.extent.maxy) _Map.extent.maxy = pEnvelope.YMax; } //rerecord the max extents m_MapMinx = _Map.extent.minx; m_MapMiny = _Map.extent.miny; m_MapMaxx = _Map.extent.maxx; m_MapMaxy = _Map.extent.maxy; classObj myClass = new classObj(pLayer); myClass.name = "random"; styleObj myStyle = new styleObj(myClass); Color pRandomColor = GetRandomColor(); myStyle.color.red = pRandomColor.R; myStyle.color.green = pRandomColor.G; myStyle.color.blue = pRandomColor.B; myStyle.opacity = 0; fmapGeometryType pGeomType = pFc.ShapeType; if ((pGeomType == fmapGeometryType.Point) || (pGeomType == fmapGeometryType.Point25D) || (pGeomType == fmapGeometryType.MultiPoint) || (pGeomType == fmapGeometryType.MultiPoint25D)) { pLayer.type = MS_LAYER_TYPE.MS_LAYER_POINT; } else if ((pGeomType == fmapGeometryType.LineString) || (pGeomType == fmapGeometryType.LineString) || (pGeomType == fmapGeometryType.MultiLineString) || (pGeomType == fmapGeometryType.MultiLineString25D)) { pLayer.type = MS_LAYER_TYPE.MS_LAYER_LINE; } else if ((pGeomType == fmapGeometryType.Polygon) || (pGeomType == fmapGeometryType.Polygon25D) || (pGeomType == fmapGeometryType.MultiPolygon) || (pGeomType == fmapGeometryType.MultiPolygon25D)) { pRandomColor = GetRandomColor(); myStyle.outlinecolor.red = pRandomColor.R; myStyle.outlinecolor.green = pRandomColor.G; myStyle.outlinecolor.blue = pRandomColor.B; pLayer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON; } else { pLayer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON; } if (pFc != null) pFc.Dispose(); } else if ((strExt == ".tif") || (strExt == ".img")) { pLayer.data = dataPath; pLayer.connectiontype = MS_CONNECTION_TYPE.MS_RASTER; pLayer.type = MS_LAYER_TYPE.MS_LAYER_RASTER; } else return false; if (OnLayerChanged != null) OnLayerChanged(null, new LayerChangedEventArgs(pLayer.index,strName, true)); RecordLayersState(); //Console.WriteLine(_Map.numlayers.ToString()); return true; }
/// <summary> /// Create a default layer for creating a preview to another layer /// </summary> /// <param name="originalMap">The original map.</param> /// <param name="originalLayer">The original layer.</param> /// <returns>The created layer object.</returns> private layerObj InitializeDefaultLayer(mapObj originalMap, layerObj originalLayer) { // create a new map object map = new mapObj(null); map.units = MS_UNITS.MS_PIXELS; map.setExtent(0, 0, this.Width, this.Height); map.width = this.Width; map.height = this.Height; outputFormatObj format = originalMap.outputformat; if (map.getOutputFormatByName(format.name) == null) map.appendOutputFormat(format); map.selectOutputFormat(originalMap.imagetype); // copy symbolset for (int i = 1; i < originalMap.symbolset.numsymbols; i++) { symbolObj origsym = originalMap.symbolset.getSymbol(i); map.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym)); } // copy the fontset string key = null; while ((key = originalMap.fontset.fonts.nextKey(key)) != null) map.fontset.fonts.set(key, originalMap.fontset.fonts.get(key, "")); // setting a default font //map.fontset.fonts.set("", // originalMap.fontset.fonts.get(originalMap.fontset.fonts.nextKey(null),"")); // insert a new layer layerObj layer = new layerObj(map); if (originalLayer != null) { // the chart type doesn't support having as single class in it if (originalLayer.type == MS_LAYER_TYPE.MS_LAYER_CHART) layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON; else layer.type = originalLayer.type; originalLayer.open(); // add the sample feature to the layer AddSampleFeature(layer, originalLayer.numitems); if (originalLayer.getResults() == null) originalLayer.close(); // close only is no query results } else { layer.type = MS_LAYER_TYPE.MS_LAYER_ANNOTATION; // add the sample feature to the layer AddSampleFeature(layer, 0); } layer.status = mapscript.MS_ON; return layer; }