[RGEOS]绘制多边形Polygon
绘制OGIS定义的Polygon
public void DrawPolygon(Polygon pol, Brush brush, Pen pen, bool clip)
{
gc = Graphics.FromHwnd(Handle);
if (pol.ExteriorRing == null)
return;
if (pol.ExteriorRing.Vertices.Count > )
{
//Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
GraphicsPath gp = new GraphicsPath(); //Add the exterior polygon
PointF[] pts = TransformLineString(pol.ExteriorRing);
if (!clip)
gp.AddPolygon(LimitValues(pts, extremeValueLimit));
else
DrawPolygonClipped(gp, pts, (int), (int)); //Add the interior polygons (holes) for (int i = ; i < pol.InteriorRings.Count; i++)
{
PointF[] pts1 = TransformLineString(pol.InteriorRings[i]);
if (!clip)
gp.AddPolygon(LimitValues(pts1, extremeValueLimit));
else
DrawPolygonClipped(gp, pts1, (int), (int));
} // Only render inside of polygon if the brush isn't null or isn't transparent
if (brush != null && brush != Brushes.Transparent)
gc.FillPath(brush, gp);
// Create an outline if a pen style is available
if (pen != null)
gc.DrawPath(pen, gp);
gc.Dispose();
}
}
public static PointF[] TransformLineString(LineString line)
{
PointF[] v = new PointF[line.Vertices.Count];
for (int i = ; i < line.Vertices.Count; i++)
v[i] = new PointF((float)line.Vertices[i].X, (float)line.Vertices[i].Y);
return v;
}
internal static PointF[] clipPolygon(PointF[] vertices, int width, int height)
{
float deltax, deltay, xin, xout, yin, yout;
float tinx, tiny, toutx, touty, tin1, tin2, tout;
float x1, y1, x2, y2; List<PointF> line = new List<PointF>();
if (vertices.Length <= ) /* nothing to clip */
return vertices; for (int i = ; i < vertices.Length - ; i++)
{
x1 = vertices[i].X;
y1 = vertices[i].Y;
x2 = vertices[i + ].X;
y2 = vertices[i + ].Y; deltax = x2 - x1;
if (deltax == )
{
// bump off of the vertical
deltax = (x1 > ) ? -nearZero : nearZero;
}
deltay = y2 - y1;
if (deltay == )
{
// bump off of the horizontal
deltay = (y1 > ) ? -nearZero : nearZero;
} if (deltax > )
{
// points to right
xin = ;
xout = width;
}
else
{
xin = width;
xout = ;
} if (deltay > )
{
// points up
yin = ;
yout = height;
}
else
{
yin = height;
yout = ;
} tinx = (xin - x1) / deltax;
tiny = (yin - y1) / deltay; if (tinx < tiny)
{
// hits x first
tin1 = tinx;
tin2 = tiny;
}
else
{
// hits y first
tin1 = tiny;
tin2 = tinx;
} if ( >= tin1)
{
if ( < tin1)
line.Add(new PointF(xin, yin)); if ( >= tin2)
{
toutx = (xout - x1) / deltax;
touty = (yout - y1) / deltay; tout = (toutx < touty) ? toutx : touty; if ( < tin2 || < tout)
{
if (tin2 <= tout)
{
if ( < tin2)
{
if (tinx > tiny)
line.Add(new PointF(xin, y1 + tinx * deltay));
else
line.Add(new PointF(x1 + tiny * deltax, yin));
} if ( > tout)
{
if (toutx < touty)
line.Add(new PointF(xout, y1 + toutx * deltay));
else
line.Add(new PointF(x1 + touty * deltax, yout));
}
else
line.Add(new PointF(x2, y2));
}
else
{
if (tinx > tiny)
line.Add(new PointF(xin, yout));
else
line.Add(new PointF(xout, yin));
}
}
}
}
}
if (line.Count > )
line.Add(new PointF(line[].X, line[].Y)); return line.ToArray();
} private void DrawPolygonClipped(GraphicsPath gp, PointF[] polygon, int width, int height)
{
ClipState clipState = DetermineClipState(polygon, width, height);
if (clipState == ClipState.Within)
{
gp.AddPolygon(polygon);
}
else if (clipState == ClipState.Intersecting)
{
PointF[] clippedPolygon = clipPolygon(polygon, width, height);
if (clippedPolygon.Length > )
gp.AddPolygon(clippedPolygon);
}
}
[RGEOS]绘制多边形Polygon的更多相关文章
- 【Silverlight】Bing Maps学习系列(五):绘制多边形(Polygon)图形(转)
[Silverlight]Bing Maps学习系列(五):绘制多边形(Polygon)图形 Bing Maps Silverlight Control支持用户自定义绘制多边形(Polygon)图形, ...
- canvas绘制多边形
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- leaflet简单例子,绘制多边形
var crs = L.CRS.EPSG900913; var map = L.map('map', { crs: crs, width: '100%', height: '100%', maxZoo ...
- 结合谷歌地图多边形(polygon)与Sql Server 2008的空间数据类型计算某个点是否在多边形内的注意事项
首先在利用 GEOGRAPHY::STPolyFromText(@GeoStr, 4326) 这样的函数把字符串转换为Geography类型时,字符串里经纬度的顺序是 “经度[空格]纬度”,即“lon ...
- 用线框模式绘制多边形 glPolygonMode
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_TRIANGLES);//开始以g_ViewMode模式绘制 glColor3ub(182. ...
- [WebGL入门]十四,绘制多边形
注意:文章翻译http://wgld.org/.原作者杉本雅広(doxas),文章中假设有我的额外说明,我会加上[lufy:].另外,鄙人webgl研究还不够深入.一些专业词语,假设翻译有误,欢迎大家 ...
- HNOI2019 多边形 polygon
HNOI2019 多边形 polygon https://www.luogu.org/problemnew/show/P5288 这题镪啊... 首先堆结论: 显然终止状态一定是所有边都连向n了 根据 ...
- Arcgis api for javascript学习笔记(4.5版本) - 点击多边形(Polygon)并高亮显示
在现在的 arcgis_js_v45_api 版本中并没有直接提供点击Polygon对象高亮显示.需要实现如下几个步骤: 1.点击地图时,获取Polygon的Graphic对象: 2.对获取到的Gra ...
- 浅谈使用canvas绘制多边形
本文主要使用坐标轴的使用来绘制多边形,点位则都是在y轴上寻找,这种方法能够更好的理解图形与修改. //id为html里canvas标签的属性id: //x,y为坐标轴的起始位置,因为canvas默认坐 ...
随机推荐
- 【液晶模块系列基础视频】3.4fatfs接口函数的使用4
============================= 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee.cnblogs.com 官方网店:ht ...
- Twitter Storm中Bolt消息传递路径之源码解读
本文初次发表于storm-cn的google groups中,现以blog的方式再次发表,表明本人徽沪一郎确实读过这些代码,:). Bolt作为task被executor执行,而executor是一个 ...
- OmniThreadLibrary 3.03b发布了
虽然版本号升的不大,但这也是一个重要的版本.作者发现了一个长期存在的bug,就是建立一个线程,如果不指定线程的优先级则默认设置为idle.(正确的应是Normal) 看一下具体的改动情况: 新功能: ...
- php面向对象之__toString()
似曾相识,在php面向对象编程之魔术方法__set,曾经介绍了什么是魔术方法,这一章又介绍一个魔术方法__tostring(). __toString()是快速获取对象的字符串信息的便捷方式,似乎魔术 ...
- CentOS + Nginx + PHP-FPM(FastCGI) 配置CodeIgniter
nginx官方现在已经针对centos提供了repository,所以现在可以直接通过yum来安装啦,很方便. nginx官方安装教程:http://nginx.org/en/download.htm ...
- find grep 组合使用
1. 查找所有".h"文件 find /PATH -name "*.h" 2. 查找所有".h"文件中的含有"helloworld ...
- openCV中IplImage的使用
http://blog.csdn.net/welcome_xu/article/details/7650680 IplImage结构详细分析 IplImage 结构解读: typedef stru ...
- SQL 编辑
局部变量: DECLARE @variable_name Datatype Variable_naem为局部变量的名称,Datatype为数据名称. 例如: DECLARE @name varchar ...
- Win7+VS2005编译Qt4.7.3+phonon(需要安装新版本Windows SDK)
Qt官网上下载的源代码在编译时并没有将phonon继承进去,只提供了源代码,而在Win7+VS2005中编译phonon时遇到不少的问题,因为phonon只是一个前端程序,要使用其实现多媒体的播放还需 ...
- 【Android测试】【第一节】性能——CPU
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5065083.html 前言 本来打算写完全部的自动化测试之 ...