Select to view content in your preferred language

[C#] How to create Line of Sight?

4778
11
Jump to solution
03-27-2013 03:42 AM
oyleiste
Regular Contributor
Hello

I'm able to load a DTED Level 0 file into a RasterDataset, color it and create a IRasterLayer from it to add into axMapControl. Here is my working code:
IWorkspaceFactory wsf = new RasterWorkspaceFactoryClass(); IRasterWorkspace rasterWS = (IRasterWorkspace)wsf.OpenFromFile(@"C:\Users\ABC\Desktop\DTED_E30N40\dted\e034", 0); rasterDS = rasterWS.OpenRasterDataset("n40.dt0");  IRasterBandCollection pRasterBandCollection = (IRasterBandCollection)rasterDS; IEnumRasterBand pEnumRasterBand = pRasterBandCollection.Bands; IRasterBand pRasterBand = pEnumRasterBand.Next(); pRasterBand.ComputeStatsAndHist(); IRasterStatistics pRasterStatistics = pRasterBand.Statistics;  IRgbColor pFromColor = new RgbColorClass(); pFromColor.Red = 20; pFromColor.Green = 20; pFromColor.Blue = 220;  IRgbColor pToColor = new RgbColorClass(); pToColor.Red = 220; pToColor.Green = 20; pToColor.Blue = 20;  IAlgorithmicColorRamp pAlgorithmicColorRamp = new AlgorithmicColorRampClass(); pAlgorithmicColorRamp.FromColor = pFromColor; pAlgorithmicColorRamp.ToColor = pToColor; pAlgorithmicColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; pAlgorithmicColorRamp.Size = 255;  bool bOK; pAlgorithmicColorRamp.CreateRamp(out bOK);  IRasterStretchColorRampRenderer pRasterStretchColorRampRenderer = new RasterStretchColorRampRendererClass(); pRasterStretchColorRampRenderer.BandIndex = 0; pRasterStretchColorRampRenderer.LabelHigh = pRasterStatistics.Maximum.ToString(); pRasterStretchColorRampRenderer.LabelLow = pRasterStatistics.Minimum.ToString(); pRasterStretchColorRampRenderer.ColorRamp = pAlgorithmicColorRamp;  IRasterLayer rasterLayer = new RasterLayer(); rasterLayer.CreateFromDataset(rasterDS); rasterLayer.Name = "DTED Level 0 [E34-N40]"; rasterLayer.Renderer = (IRasterRenderer)pRasterStretchColorRampRenderer; axMapControl1.AddLayer(rasterLayer);

The result is this screenshot of axMapControl:[ATTACH=CONFIG]22980[/ATTACH]

Now, I want to create Line of Sight; between observer and a point. How can I do that? I have no idea unfortunately.

Thanks
0 Kudos
1 Solution

Accepted Solutions
JasonPike
Frequent Contributor
Lines of sight can be calculated by calling ISurface.GetLineOfSight.


And there you have it :D.

This has some implementation details you might be interested in:
http://forums.esri.com/Thread.asp?c=93&f=993&t=192554

View solution in original post

0 Kudos
11 Replies
oyleiste
Regular Contributor
By the way, I found this class: LineOfSight Class
but I don't have ESRI.ArcGIS.Analyst3DTools namespace. Why?
I don't either have ESRI.ArcGIS.SpatialAnalystTools to use ViewShed Class.
Any idea about adding these namespaces?

Sincerely
0 Kudos
JasonPike
Frequent Contributor
By the way, I found this class: LineOfSight Class
but I don't have ESRI.ArcGIS.Analyst3DTools namespace. Why?
I don't either have ESRI.ArcGIS.SpatialAnalystTools to use ViewShed Class.
Any idea about adding these namespaces?

Sincerely


You have to add a reference to Analyst3DTools to your project.

1) Right-click References in your project
2) Click Add Reference
3) Select the .NET tab
4) Select ESRI.ArcGIS.Analyst3DTools
5) Click OK

Do the same for ESRI.ArcGIS.SpatialAnalysisTools.
0 Kudos
oyleiste
Regular Contributor
You have to add a reference to Analyst3DTools to your project.
1) Right-click References in your project
2) Click Add Reference
3) Select the .NET tab
4) Select ESRI.ArcGIS.Analyst3DTools
5) Click OK


Thank you very much for your reply.

Well, do you have any idea about using LineOfSight or ViewShed class? How to set observer and point?

By the way, both namespaces (ESRI.ArcGIS.Analyst3DTools & ESRI.ArcGIS.SpatialAnalysisTools) has ViewShed class. I'll use Analyst3DTools' class.

Thank again 🙂
0 Kudos
JasonPike
Frequent Contributor
Thank you very much for your reply.

Well, do you have any idea about using LineOfSight or ViewShed class? How to set observer and point?

By the way, both namespaces (ESRI.ArcGIS.Analyst3DTools & ESRI.ArcGIS.SpatialAnalysisTools) has ViewShed class. I'll use Analyst3DTools' class.

Thank again 🙂


I don't think I fully understand what you are trying to do. The classes you mention seem to be for use in ArcGlobe, but you mentioned AxMapControl, which I think is for use in ArcMap. I'm new to ArcGIS, so those might be bad assumptions. Can you post a picture of what you're trying to accomplish?
0 Kudos
oyleiste
Regular Contributor
Well, you are right 😄
After a lot of googling, I found out that I need "Linear Line of Sight", based on my DTED data. You can see the screenshot I posted earlier. How can I get linear Line of Sight between two points?

Thanks
0 Kudos
JasonPike
Frequent Contributor
Well, you are right 😄
After a lot of googling, I found out that I need "Linear Line of Sight", based on my DTED data. You can see the screenshot I posted earlier. How can I get linear Line of Sight between two points?

Thanks


Unfortunately, all I've been able to find is the Military Analyst extension, which I think is for ArcGlobe: http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Using_the_Linear_Line_of_Sight

If you have licenses for ArcGlobe and Military Analyst, I would use them.

I haven't seen any API for calculating LLOS in ArcMap, but that doesn't mean it doesn't exist. I'm sure custom code can be written to do this, but I can't promise I'd have enough time to help you very much with writing it.
0 Kudos
NeilClemmons
Honored Contributor
Lines of sight can be calculated by calling ISurface.GetLineOfSight.
0 Kudos
JasonPike
Frequent Contributor
Lines of sight can be calculated by calling ISurface.GetLineOfSight.


And there you have it :D.

This has some implementation details you might be interested in:
http://forums.esri.com/Thread.asp?c=93&f=993&t=192554
0 Kudos
oyleiste
Regular Contributor
And there you have it :D.

This has some implementation details you might be interested in:
http://forums.esri.com/Thread.asp?c=93&f=993&t=192554


Thank you very much Neil; for mentioning ISurface and thank you ScJpike; for your helpful link 🙂

Now, I'm able to get linear line of sight of two points, as you see: [ATTACH=CONFIG]23004[/ATTACH]

Well, is there any way to give observer's Z (elevation) and get line of sight of that point with given Z (not the elevation in DTED)? Imagine that I want to get LLOS of a helicopter that abviously it's elevation is greater that DTED's elevation of that point.
Or it's only possible with DTED elevations? Any idea?

Thank you very much guys
Sincerely
0 Kudos