public static void Main(string[] args) { if (args.Length != 1) { usage(); } shapefileObj sf_obj = new shapefileObj(args[0], -1); shapeObj s_obj = new shapeObj(-1); for (int i = 0; i < sf_obj.numshapes; i++) { sf_obj.get(i, s_obj); Console.WriteLine("Shape " + i + " has " + s_obj.numlines + " part(s)"); Console.WriteLine("bounds (" + s_obj.bounds.minx + ", " + s_obj.bounds.miny + ") (" + s_obj.bounds.maxx + ", " + s_obj.bounds.maxy + ")"); for (int j = 0; j < s_obj.numlines; j++) { lineObj l_obj = s_obj.get(j); Console.WriteLine("Part " + j + " has " + l_obj.numpoints + " points."); for (int k = 0; k < l_obj.numpoints; k++) { pointObj p_obj = l_obj.get(k); Console.WriteLine(k + ": " + p_obj.x + ", " + p_obj.y); } } } }
internal static HandleRef getCPtrAndSetReference(lineObj obj, object parent) { if (obj != null) { obj.swigParentRef = parent; return obj.swigCPtr; } else { return new HandleRef(null, IntPtr.Zero); } }
internal static HandleRef getCPtrAndDisown(lineObj obj, object parent) { if (obj != null) { obj.swigCMemOwn = false; obj.swigParentRef = parent; return obj.swigCPtr; } else { return new HandleRef(null, IntPtr.Zero); } }
public int add(lineObj line) { int ret = mapscriptPINVOKE.shapeObj_add(swigCPtr, lineObj.getCPtr(line)); if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve(); return ret; }
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(); } } }
internal static HandleRef getCPtr(lineObj obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; }
/// <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> /// Converts the GDI+ GraphicsPath to the MapScript shape object. /// </summary> /// <param name="path">The GraphicsPath object to convert.</param> /// <returns>The converted shapeObj</returns> public shapeObj GraphicsPathToShape(GraphicsPath path) { shapeObj feature = null; if (path != null) { using (GraphicsPathIterator myPathIterator = new GraphicsPathIterator(path)) { int myStartIndex; int myEndIndex; bool myIsClosed; // get the number of Subpaths. int numSubpaths = myPathIterator.SubpathCount; while (myPathIterator.NextSubpath(out myStartIndex, out myEndIndex, out myIsClosed) > 0) { lineObj line = new lineObj(); for (int i = myStartIndex; i <= myEndIndex; i++) { if (i == myStartIndex || (path.PathPoints[i].X != path.PathPoints[i - 1].X && path.PathPoints[i].Y != path.PathPoints[i - 1].Y)) line.add(new pointObj(Pixel2MapX(path.PathPoints[i].X), Pixel2MapY(path.PathPoints[i].Y), 0, 0)); } if (feature == null) { if (myIsClosed && line.numpoints > 2) feature = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POLYGON); else feature = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_LINE); } if (line.numpoints >= 2) feature.add(line); } } } return feature; }
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 int setPoints(lineObj line) { int ret = mapscriptPINVOKE.symbolObj_setPoints(swigCPtr, lineObj.getCPtr(line)); if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve(); return ret; }