コード例 #1
0
    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);
                }
            }
        }
    }
コード例 #2
0
ファイル: SelectList.cs プロジェクト: xiver/MapManager
 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);
     }
 }
コード例 #3
0
ファイル: SelectList.cs プロジェクト: xiver/MapManager
 private void centerToShapeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (listView.SelectedItems.Count > 0 && PositionChanged != null)
     {
         shapeObj shape = (shapeObj)listView.SelectedItems[0].SubItems[1].Tag;
         pointObj pos   = shape.getCentroid();
         PositionChanged(this, pos.x, pos.y);
     }
 }
コード例 #4
0
 internal static HandleRef getCPtrAndSetReference(shapeObj obj, object parent) {
   if (obj != null)
   {
     obj.swigParentRef = parent;
     return obj.swigCPtr;
   }
   else
   {
     return new HandleRef(null, IntPtr.Zero);
   }
 }
コード例 #5
0
 internal static HandleRef getCPtrAndDisown(shapeObj obj, object parent) {
   if (obj != null)
   {
     obj.swigCMemOwn = false;
     obj.swigParentRef = parent;
     return obj.swigCPtr;
   }
   else
   {
     return new HandleRef(null, IntPtr.Zero);
   }
 }
コード例 #6
0
ファイル: shpdump.cs プロジェクト: RodrigoVazquez/mapserver
  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);							
		}
	  }	  
    }
  }
コード例 #7
0
 public int disjoint(shapeObj shape) {
   int ret = mapscriptPINVOKE.shapeObj_disjoint(swigCPtr, shapeObj.getCPtr(shape));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #8
0
 public int contains(shapeObj shape) {
   int ret = mapscriptPINVOKE.shapeObj_contains__SWIG_0(swigCPtr, shapeObj.getCPtr(shape));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #9
0
 public shapeObj symDifference(shapeObj shape) {
   IntPtr cPtr = mapscriptPINVOKE.shapeObj_symDifference(swigCPtr, shapeObj.getCPtr(shape));
   shapeObj ret = (cPtr == IntPtr.Zero) ? null : new shapeObj(cPtr, true, ThisOwn_true());
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #10
0
 internal static HandleRef getCPtr(shapeObj obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
コード例 #11
0
 public int copy(shapeObj dest) {
   int ret = mapscriptPINVOKE.shapeObj_copy(swigCPtr, shapeObj.getCPtr(dest));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #12
0
 public int addFeature(shapeObj shape) {
   int ret = mapscriptPINVOKE.layerObj_addFeature(swigCPtr, shapeObj.getCPtr(shape));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #13
0
 public int queryByShape(shapeObj shape) {
   int ret = mapscriptPINVOKE.mapObj_queryByShape(swigCPtr, shapeObj.getCPtr(shape));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #14
0
 public int getClassIndex(mapObj map, shapeObj shape, SWIGTYPE_p_int classgroup, int numclasses) {
   int ret = mapscriptPINVOKE.layerObj_getClassIndex(swigCPtr, mapObj.getCPtr(map), shapeObj.getCPtr(shape), SWIGTYPE_p_int.getCPtr(classgroup), numclasses);
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #15
0
ファイル: MapControl.cs プロジェクト: 4g0st1n0/MapManager
 /// <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);
         }
     }
 }
コード例 #16
0
ファイル: MapControl.cs プロジェクト: 4g0st1n0/MapManager
        /// <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;
        }
コード例 #17
0
ファイル: MapControl.cs プロジェクト: 4g0st1n0/MapManager
 /// <summary>
 /// Converts the MapScript shape object to the GDI+ GraphicsPath.
 /// </summary>
 /// <param name="feature">The shapeObj to conver.</param>
 /// <returns>The converted GraphicsPath object</returns>
 public static GraphicsPath ShapeToGraphicsPath(shapeObj feature)
 {
     GraphicsPath path = new GraphicsPath();
     path.Reset();
     if (feature != null)
     {
         lineObj line;
         pointObj point;
         for (int i = 0; i < feature.numlines; i++)
         {
             path.StartFigure();
             line = feature.get(i);
             for (int j = 0; j < line.numpoints; j++)
             {
                 point = line.get(j);
                 PointF[] pts =  { new PointF((float)point.x, (float)point.y) };
                 path.AddLines(pts);
             }
             if (feature.type == (int)MS_SHAPE_TYPE.MS_SHAPE_POLYGON) path.CloseFigure();
         }
     }
     return path;
 }
コード例 #18
0
 public double distanceToShape(shapeObj shape) {
   double ret = mapscriptPINVOKE.shapeObj_distanceToShape(swigCPtr, shapeObj.getCPtr(shape));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #19
0
    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();
          }
          }
    }
コード例 #20
0
 public int getTransformed(mapObj map, int i, shapeObj shape) {
   int ret = mapscriptPINVOKE.shapefileObj_getTransformed(swigCPtr, mapObj.getCPtr(map), i, shapeObj.getCPtr(shape));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #21
0
ファイル: inline.cs プロジェクト: offroad-bis/mapserver
    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();
            }
        }
    }