[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默认坐 ...
随机推荐
- 【新产品发布】EVC8003 磁耦隔离型USB转全功能RS-232
============================== 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee.cnblogs.com 官方网店:h ...
- html5+css3
1,文件声明,<!Doctype>,不再有严格模式和混杂模式 2语意的标签 1,header 头 section中 nav导航(中上) aside侧边栏(中左) article内容(中右) ...
- 对.net系统架构改造的一点经验和教训(转)
在互联网行业,基于Unix/Linux的网站系统架构毫无疑问是当今主流的架构解决方案,这不仅仅是因为Linux本身足够的开放性,更因为围绕传统Unix/Linux社区有大量的成熟开源解决方案,覆盖了网 ...
- SharedPreferences封装类SPUtils
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.uti ...
- C与C++连续赋值的区别
int a,b,c,d; a = b = ; // ( a!=b?a:b) = 1000;//如果a不等于b 那么a = 100;这句话执行完 a还是等于5,b= 100: printf(" ...
- 【转载】在LoadRunner向远程Linux/Unix执行命令行并收集性能数据
前面介绍过在LoadRunner的Java协议实现“使用SSH连接Linux”,当然连接之后的故事由你主导. 今天要讲的,是一个非Java版本.是对“在LoadRunner中执行命令行程序之:pope ...
- java 客户端获取真实ip地址
在开发工作中,我们常常需要获取客户端的IP.一般获取客户端的IP地址的方法是:request.getRemoteAddr();但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实 ...
- 【iTerm2】美化你的Terminal 赠佛祖像
我们开发就是喜欢各种酷炫的东西,对于有洁癖的我,连命令行都不放过了 先上图看效果,命令行显示高亮部分 实现过程: 第一步:.bash_prompt脚本 # ~/.bash_prompt # This ...
- Bluetooth HFP介绍
目录 1. 介绍 1.1 目的 1.2 使用场景 1.3 依赖关系 1.4 协议栈 1.5 角色 2. 应用层 3. 空白章节 4. 互操作性要求 4.1 介绍 4.2 Service Level C ...
- python标准库介绍
操作系统接口 os模块提供了不少与操作系统相关联的函数. >>> import os >>> os.getcwd() # 返回当前的工作目录 'C:\\Python ...