|
Does anyone know a mathematical formula (which can be translated to C #) to check if a polygon is inside another polygon?
|
|
|
|
|
Regular polygons (where all the angles or equal) or irregular?
Needless to say, irregular ones are the PITA...especially where they are the containing polygon.
Just to confirm how much of a PITA irregular polygons are, here's a discussion that may may like to read (though you'll probably wish you hadn't)
The Polygon Containment Problem[^]
modified 28-Jan-13 14:17pm.
|
|
|
|
|
There are irregular polygons.
|
|
|
|
|
If polygon A is inside polygon B, then:
1. Every vertex of A will be inside B, and
2. No edge of A will intersect an edge of B.
So you need two subroutines: One to detect if a point is in a polygon, and one to detect if two line segments intersect each other.
Test all points of A to see if they're in B. If one isn't, then B doesn't contain A. Then test all edges of A to see if any intersect an edge of B. If none do, then polygon A is inside polygon B.
|
|
|
|
|
Yes you are right, but this is a very costly routine, and it might be performed more than 1000 times during the opening of a shapefile.
|
|
|
|
|
So you need efficiency too. Ok, calculate the bounding rectangles of both polygons. If the bounding rectangles don't overlap, neither polygon contains the other, so you can skip the more expensive test.
If they do overlap, check if each polygon contains points of the other in the overlap region. If polygon B contains some points of polygon A, but not others, then B doesn't contain A.
|
|
|
|
|
Hello ,
I am posting on the server side application using a "Response.Write(str)" statement, where "str" contains some XML code .
On the client side I am getting the response using a HttpWebResponse .
When I get the HttpWebResponse content , I find , apart from the correct XML code that I posted on server side, soem kind of strange trailer which resembles an Html page, but is absolutely random (I mean , this "html page" changes from session to session...) .
What is the reason of this strange result ? I am posting some relevant code below to help explain :
Server side :
Resp = ....some XML code ....
Response.Write(Resp);
Client side :
HttpWebRequest WR = (HttpWebRequest)(WebRequest.Create(url));
HttpWebResponse Resp = (HttpWebResponse)WR.GetResponse();
Stream RS = Resp.GetResponseStream();
StreamReader SR = new StreamReader(RS);
string mess = SR.ReadToEnd();
Resp.Close();
textBoxResponse.Text = mess;
Thank you in advance
Leo
|
|
|
|
|
I'm guessing that you're calling Response.Write from the code-behind of an ASP.NET page? In which case, the content of the page will still be output to the response after the text you've passed to the Response.Write method. You'll need to call Response.End after your last call to Response.Write to prevent this.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I followed your instructions and now it works correctly.... I think I need to study better the way a web application works ....
Thank you very much.
Leo
|
|
|
|
|
Hi,
I have a question: I am want to add text (many strings) into file by using the method TextWriter.Write(), will this method append text into a file or overwrite the content of file ?
Are there any other ways to append text into file ?
Thanks and regards,
|
|
|
|
|
A writer will write its content at the current file location, and move the current location to the end of the written content. In typical usage this means that it will append each time you call it.
|
|
|
|
|
Using a StreamWriter [^] is generally a better choice. When you open the underlying FileStream you can specify whether to append or not by the mode option[^].
|
|
|
|
|
The TextWriter don't care. The state of the underlying Stream is what matters -- it can be opened to append or overwrite.
|
|
|
|
|
Thanks all of you.
I used StreamWriter for this.
Kind regards,
|
|
|
|
|
Hi All,
I have created an asp.net c# website that is being used like a helpdesk, tickets are being logged and resolved etc.
I now want to add a pop up that should appear on the user that logged the tickets' pc when the IT personnel updates the ticket.
I am not sure how or if you can use notifyicon to do this?
|
|
|
|
|
You would need to install an application on their machine which talked to the ticket server. There's no way to do that simply through a web interface.
|
|
|
|
|
Thank you for the response!
How would the application know which tickets belong to which user? - I have a username linked to the ticket and a ticket number.
Sorry if I sound stupid!
I don't know much about c# applications, I have only worked with websites.
|
|
|
|
|
If the user name was linked to their Windows Identity, then you can use that. If, however, your site uses a custom login mechanism or something like OAuth, then the user is going to have to associate their identity with the notification application - this would typically require you to provide a settings page where they entered their user name and password details so that you could verify that they were a valid user.
To be honest, this opens a whole can of worms, including things such as verifying that web service requests haven't been intercepted and so on. A simpler method would just be to email them.
|
|
|
|
|
Thank you so much!
I would just use email, but my company wants the pop up. They want to move away from emails.
I think I found my solution!
|
|
|
|
|
NickyRamshaw wrote: I think I found my solution!
Only if the user has a Windows machine. What do you do if they only ever use an iPad? Or how about those few people using WinRT? Perhaps they only use Linux boxes.
|
|
|
|
|
how i can convert this code from java to c#
public static String Dcipher(String encryptedText1) {
try {
byte[] desKeyData = {(byte) 0x01, (byte) 0x02, (byte) 0x03,
(byte) 0x04, (byte) 0x05, (byte) 0x06,
(byte) 0x07, (byte) 0x08};
DESKeySpec desKeySpec = new DESKeySpec(desKeyData);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = null;
try {
key = keyFactory.generateSecret(desKeySpec);
} catch (InvalidKeySpecException ex1) {
}
byte[] initVector = new byte[] {0x10, 0x10, 0x01, 0x04, 0x01, 0x01,
0x01,
0x02};
AlgorithmParameterSpec algParamSpec = new IvParameterSpec(
initVector);
Cipher m_decrypter = Cipher.getInstance("DES/OFB32/NoPadding");
m_decrypter.init(Cipher.DECRYPT_MODE, key, algParamSpec);
byte[] encryptedText = encryptedText1.getBytes();
byte[] decryptedText = m_decrypter.doFinal(encryptedText);
return (new String(decryptedText));
} catch (BadPaddingException ex) {
ex.printStackTrace();
} catch (IllegalBlockSizeException ex) {
ex.printStackTrace();
} catch (InvalidAlgorithmParameterException ex) {
ex.printStackTrace();
} catch (InvalidKeyException ex) {
ex.printStackTrace();
} catch (NoSuchPaddingException ex) {
ex.printStackTrace();
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
return "";
}
|
|
|
|
|
|
I don't have a conversion for some of the Java types you're using, but the following syntax should be correct:
public static string Dcipher(string encryptedText1)
{
try
{
sbyte[] desKeyData = {(sbyte) 0x01, (sbyte) 0x02, (sbyte) 0x03, (sbyte) 0x04, (sbyte) 0x05, (sbyte) 0x06, (sbyte) 0x07, (sbyte) 0x08};
DESKeySpec desKeySpec = new DESKeySpec(desKeyData);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = null;
try
{
key = keyFactory.generateSecret(desKeySpec);
}
catch (InvalidKeySpecException ex1)
{
}
sbyte[] initVector = new sbyte[] {0x10, 0x10, 0x01, 0x04, 0x01, 0x01, 0x01, 0x02};
AlgorithmParameterSpec algParamSpec = new IvParameterSpec(initVector);
Cipher m_decrypter = Cipher.getInstance("DES/OFB32/NoPadding");
m_decrypter.init(Cipher.DECRYPT_MODE, key, algParamSpec);
sbyte[] encryptedText = encryptedText1.Bytes;
sbyte[] decryptedText = m_decrypter.doFinal(encryptedText);
return (new string(decryptedText));
}
catch (BadPaddingException ex)
{
Console.WriteLine(ex.ToString());
Console.Write(ex.StackTrace);
}
catch (IllegalBlockSizeException ex)
{
Console.WriteLine(ex.ToString());
Console.Write(ex.StackTrace);
}
catch (InvalidAlgorithmParameterException ex)
{
Console.WriteLine(ex.ToString());
Console.Write(ex.StackTrace);
}
catch (InvalidKeyException ex)
{
Console.WriteLine(ex.ToString());
Console.Write(ex.StackTrace);
}
catch (NoSuchPaddingException ex)
{
Console.WriteLine(ex.ToString());
Console.Write(ex.StackTrace);
}
catch (NoSuchAlgorithmException ex)
{
Console.WriteLine(ex.ToString());
Console.Write(ex.StackTrace);
}
return "";
}
Dave Doknjas
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
Instant C# - VB to C# Converter
Instant VB - C# to VB Converter
|
|
|
|
|
I am getting a timeout message when accessing a linq to sql object in a C# 2010 application. This error message is occuring when I am doing a select in the linq to sql object. thus can you tell me how I can increase the timeout on the linq to sql data set object? The following os the error message I am getting:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
2013-01-24 16:40:03.3082|ERROR|Sample|************* Stack Trace *******************
2013-01-24 16:40:03.3238|ERROR|Sample| at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
|
|
|
|
|
You may be causing the exception yourself, if it happens after a period of time or after a number of connection attempts. Try reading this[^] for a brief discussion on the topic.
If it's the first connection attempt your code makes to the database, you've got a problem with your connection string or the database engine isn't responding for some reason or ...
|
|
|
|
|