绘制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的更多相关文章

  1. 【Silverlight】Bing Maps学习系列(五):绘制多边形(Polygon)图形(转)

    [Silverlight]Bing Maps学习系列(五):绘制多边形(Polygon)图形 Bing Maps Silverlight Control支持用户自定义绘制多边形(Polygon)图形, ...

  2. canvas绘制多边形

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. leaflet简单例子,绘制多边形

    var crs = L.CRS.EPSG900913; var map = L.map('map', { crs: crs, width: '100%', height: '100%', maxZoo ...

  4. 结合谷歌地图多边形(polygon)与Sql Server 2008的空间数据类型计算某个点是否在多边形内的注意事项

    首先在利用 GEOGRAPHY::STPolyFromText(@GeoStr, 4326) 这样的函数把字符串转换为Geography类型时,字符串里经纬度的顺序是 “经度[空格]纬度”,即“lon ...

  5. 用线框模式绘制多边形 glPolygonMode

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_TRIANGLES);//开始以g_ViewMode模式绘制 glColor3ub(182. ...

  6. [WebGL入门]十四,绘制多边形

    注意:文章翻译http://wgld.org/.原作者杉本雅広(doxas),文章中假设有我的额外说明,我会加上[lufy:].另外,鄙人webgl研究还不够深入.一些专业词语,假设翻译有误,欢迎大家 ...

  7. HNOI2019 多边形 polygon

    HNOI2019 多边形 polygon https://www.luogu.org/problemnew/show/P5288 这题镪啊... 首先堆结论: 显然终止状态一定是所有边都连向n了 根据 ...

  8. Arcgis api for javascript学习笔记(4.5版本) - 点击多边形(Polygon)并高亮显示

    在现在的 arcgis_js_v45_api 版本中并没有直接提供点击Polygon对象高亮显示.需要实现如下几个步骤: 1.点击地图时,获取Polygon的Graphic对象: 2.对获取到的Gra ...

  9. 浅谈使用canvas绘制多边形

    本文主要使用坐标轴的使用来绘制多边形,点位则都是在y轴上寻找,这种方法能够更好的理解图形与修改. //id为html里canvas标签的属性id: //x,y为坐标轴的起始位置,因为canvas默认坐 ...

随机推荐

  1. 分布式架构高可用架构篇_07_MySQL主从复制的配置(CentOS-6.7+MySQL-5.6)

    参考: 龙果学院http://www.roncoo.com/share.html?hamc=hLPG8QsaaWVOl2Z76wpJHp3JBbZZF%2Bywm5vEfPp9LbLkAjAnB%2B ...

  2. 简单实现Redis缓存中的排序功能

    1.在实现缓存排序功能之前,必须先明白这一功能的合理性.不妨思考一下,既然可以在数据库中排序,为什么还要把排序功能放在缓存中实现呢?这里简单总结了两个原因:首先,排序会增加数据库的负载,难以支撑高并发 ...

  3. Centos 6.4 python 2.6 升级到 2.7

    Centos 6.4 python 2.6 升级到 2.7 分类: Python Linux2013-09-13 21:35 37278人阅读 评论(2) 收藏 举报 一开始有这个需求,是因为用 Ya ...

  4. GitHub超详细图文攻略

    GitHub超详细图文攻略 - Git客户端下载安装 GitHub提交修改源码工作流程 Git 分类: 转载2014-03-25 21:10 10641人阅读 评论(2) 收藏 举报 GitHubbr ...

  5. 依赖注入Bean属性

    一.Bean属性依赖注入 对于类成员变量,注入方式有三种 •构造函数注入 •属性setter方法注入 •接口注入 Spring支持前两种 1.构造函数 属性注入 使用构造方法注入,在Spring配置文 ...

  6. GZip压缩的js文件IE6下面不能包含<script>标签

    IE6下面,GZip压缩的js文件,如果js中包含<script>标签,一遇到这样的标签,后面的内容居然都截断了,狂晕! 花了我一个晚上来找原因.. 需要将字符串'<script&g ...

  7. postgressql安装

    参考文章 FreeBSD10.0下ports安装postgresql9.4-server: http://download.csdn.net/detail/machen_smiling/8425613 ...

  8. java中关于集合的知识点梳理

    一:概述 1.集合的特点 只存储对象,集合长度是可变的,集合可以存储不同类型的对象. 2.集合框架     Collection    List | | Set ArrayList    Linked ...

  9. 利用HTML5的canvas制作万花筒动画特效

    <!DOCTYPE HTML> <html> <head> <style> #canvas{ background-color:#cccccc; } & ...

  10. Qt使用一个事件队列对所有发出的事件进行维护(QObject的event()函数相当于dispatch函数),用EventLabel 继承QLabel作为例子(简单明了) good

    事件(event)是由系统或者 Qt 本身在不同的时刻发出的.当用户按下鼠标.敲下键盘,或者是窗口需要重新绘制的时候,都会发出一个相应的事件.一些事件在对用户操作做出响应时发出,如键盘事件等:另一些事 ...