[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默认坐 ...
随机推荐
- IOS开发之开篇--CocoaPods安装
CocoaPods是什么?当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用到其他类库,所以要使用它,必须得另外下载其他类库,而其 ...
- 采用HSV生成随机颜色
使用hsv/hsb生成随机颜色,并排除靠近黑白两色的色值 public static String randomColor(){ int max = 25500000 ; Random rand = ...
- PHP获取某远程网站的服务器时间
<?php function get_time($server){ $data = "HEAD / HTTP/1.1\r\n"; $data .= "Host: ...
- javaWeb中struts开发——Bean标签
1.struts标签库中常用标签 使用myeclise标签可以自动注入,其中,前三个是经常使用的,主要的是logic标签 2.Bean标签 Bean标签主要用来定义和访问JavaBean,在Strut ...
- Flink DataSet API Programming Guide
https://ci.apache.org/projects/flink/flink-docs-release-0.10/apis/programming_guide.html Example ...
- 统计学习方法笔记 -- Boosting方法
AdaBoost算法 基本思想是,对于一个复杂的问题,单独用一个分类算法判断比较困难,那么我们就用一组分类器来进行综合判断,得到结果,"三个臭皮匠顶一个诸葛亮" 专业的说法, 强可 ...
- epoll 应用
/* * test_bittube.cpp * * Created on: 2015年7月13日 * Author: ting.guit */ #include <bind ...
- HttpWebResponse返回信息
CharacterSet "ISO-8859-1" string 获取响应的字符集. 这个目前不知道是干嘛用的 ContentEncoding "" strin ...
- awk统计nginx日志访问前一百的ip
访问ip awk '{print $1}' access.log| sort | uniq -c | sort -n -k 1 -r | head -n 100 访问地址 awk '{print $ ...
- windows下安装nodejs尝尝鲜
放Node.js作者镇楼! 1.下载对应的安装文件:http://nodejs.cn/download/ 2.自定义安装到D:\Program Files\nodejs,Add To Path一定要选 ...