Hard to say without knowing what x1, y1, x2, y2 and length are. One thing to check is that you have set MapBasic’s coordinate system prior to using the Distance function (use the ‘Set Coordsys…’ statement).
HTH,
Tom Bacon
GIS Engineer, Mouchel
T 01444 472380 │ E thomas...@mouchel.com │ W www.mouchel.com
Our values: innovation │ excellence │ integrity │ responsibility
--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en
---
You received this message because you are subscribed to the Google Groups
"MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Mouchel Limited (Mouchel) is registered in England and Wales with registered number 01686040 at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX. The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. No contracts may be concluded on behalf of Mouchel by means of email communications. Mouchel reserves the right to monitor and intercept emails sent and received on our network. |
Is "length" a reserved word in MB? I can't remember but it would seem to make sense. Try changing the name of that variable.
Regards,
Warren Vick
Europa Technologies Ltd.
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Frank Fica
Sent: 18 April 2013 2:45 PM
To: mapi...@googlegroups.com
Subject: [MI-L] Unrecognized command: (.
Does anyone know why am I getting Unrecognized command: (.
It is happening on:
length = Distance(x1,y1,x2,y2,"km")
--
Nope, I think length is ok to use. I just dumped this into the mapbasic window and it was happy with it:
Dim length as Integer
length = 20
print length
Pretty sure it should compile if it works in the MB window?
Tom Bacon
GIS Engineer, Mouchel
T 01444 472380 │ E thomas...@mouchel.com │ W www.mouchel.com
Our values: innovation │ excellence │ integrity │ responsibility
Hi Thomas,
Yes, it works in a MB program too so that's definitely not it. If there is something wrong with your x1/y1/x2/y2 variables, it's odd that it does generate a type mismatch error. What data type are they?
Another thing to check is the line before. Sometime a stray character on the end can generate an error associated with the wrong line.
Regards,
Warren
If you are getting this during compilation it’s probably caused by something further up in the code or, one or more of your variables having not been declared. Also, you should avoid using variable names like “length” as this will be a reserved word in many languages (can’t remember if it is in MB) you should use something like fltLength or iLength to indicate the field type.
Hope this helps
Regards
Adrian Gray
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Frank Fica
Sent: 18 April 2013 14:45
To: mapi...@googlegroups.com
Subject: [MI-L] Unrecognized command: (.
Does anyone know why am I getting Unrecognized command: (.
It is happening on:
length = Distance(x1,y1,x2,y2,"km")
--
Include "MAPBASIC.DEF"
Dim x1, x2, y1, y2, dY As Float
Dim length, bearing, distance As Float
Dim new_pnt As Object
Dim new_pnt_x, new_pnt_y As Float
Dim earthR as Integer ' Radius of Earth
Define PI 3.141593
Declare Function Atn2(ByVal y As Float, ByVal x as Float) As Float
Declare Sub Main
Sub Main
earthR = 6371
distance = 0.001
Fetch Rec 10842 From AllRoads_segments
Dim recID as Integer
recID = AllRoads_segments.ROAD_ID
Select * From AllRoads_segments Where ROAD_ID = recID
Dim nPoly as Integer
nPoly = ObjectInfo(AllRoads_segments.obj, 21)
print "# Segments: " + nPoly
x1 = -89.7654 'ObjectNodeX(AllRoads_segments.obj, 1, 1) ' Longitude of first node on first segment
y1 = 14.3456 'ObjectNodeY(AllRoads_segments.obj, 1, 1) ' Latitude of first node on first segment
x2 = -89.8765 'ObjectNodeX(AllRoads_segments.obj, 1, 2) ' Longitude of second node on first segment
y2 = 14.8765 'ObjectNodeY(AllRoads_segments.obj, 1, 2)
length = ObjectLen(AllRoads_segments.obj,"km")
dY = Distance(x2,y2,x2,y1,"km")
'Calculate angle, with zero degrees being east-west. Uses if/then for
'horizontal and vertical lines because of an apparent MapInfo bug that
'occasionally causes error when taking Asin(1).
If Dy/f_length = 0 Then 'Horizontal line
bearing = 0
Elseif Dy/f_length = 1 Then 'Vertical line
bearing = 90
Else
bearing = Asin(Dy/f_length)
End If
print "ROAD_ID: " + recID
print "Length in meters: " + length
print "Bearing: " + bearing * RAD_2_DEG + " degrees"
'new_pnt_x = Mod(lon1-Asin(Sin(bearing)*Sin(distance)/Cos(Lat1))+PI,2*PI)-PI
new_pnt_y = Asin(Sin(y1) * Cos(distance/earthR) + Cos(y1) * Sin(distance/earthR) * Cos(bearing))
print "Longitude: " + new_pnt_x
print "Latitude: " + new_pnt_y
Create Point Into Variable new_pnt(new_pnt_x, new_pnt_y)
Insert Into AllRoads_segments_first (obj) Values (new_pnt)
End Sub
Function Atn2(ByVal x As Float, ByVal y As Float) As Float
Dim a As Float
If (abs(x) > abs(y)) Then
a = atn (y/x)
Else
a = atn (x/y)
If a < 0 Then
a = -PI/2 - a
Else
a = PI/2 -a
End If
End If
If x < 0 Then
If y < 0 Then
a = a - PI
Else
a = a + PI
End If
Atn2 = a
End If
End Function
Frank,
I managed to get it to compile with SphericalDistance(). Not sure why it’s not working with the Distance function…
Tom Bacon
GIS Engineer, Mouchel
T 01444 472380 │ E thomas...@mouchel.com │ W www.mouchel.com
Our values: innovation │ excellence │ integrity │ responsibility
--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en
---
You received this message because you are subscribed to the Google Groups
"MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Frank,
Variables declared outside a sub/function scope should be declare using Global
Regards
Adrian
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Frank Fica
Sent: 18 April 2013 15:14
To: mapi...@googlegroups.com
Subject: [MI-L] Re: Unrecognized command: (.
Thanks for all the replies, this is code I'm trying out. It is a little bit messy but I'm posting all the code for you to analyze. If I write a new program with:
--
Yep. You could also store the command into a string variable and run it with ‘Run Command…’ which would get you around the compile issue.
Tom Bacon
GIS Engineer, Mouchel
T 01444 472380 │ E thomas...@mouchel.com │ W www.mouchel.com
Our values: innovation │ excellence │ integrity │ responsibility
From: mapi...@googlegroups.com
[mailto:mapi...@googlegroups.com] On Behalf Of Frank Fica
Sent: 18 April 2013 15:30
To: mapi...@googlegroups.com
Subject: [MI-L] Re: Unrecognized command: (.
Thanks Tom, I will give it a try. Weird ah?
--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en
---
You received this message because you are subscribed to the Google Groups
"MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Is there a specific reason for that Adrian (I’m not questioning it, just curious)? I’ve never declared my module-scope variables as Global, only those which I need across modules.
Tom Bacon
GIS Engineer, Mouchel
T 01444 472380 │ E thomas...@mouchel.com │ W www.mouchel.com
Our values: innovation │ excellence │ integrity │ responsibility
What version of MB & MI Pro are you using?
Also did you notice you are asking for the distance as X2, Y2, X2, Y1 – did you mean X2, Y2, X1, Y1?
As good practice you should also set your MapBasic session Projection and Distance and Area Units.
Just a thought ------- I’m not aware of a requirement in MB which require Projection, Distance and Area units to have been set before legacy commands like Distance but perhaps it has become dependent and that’s why SphericalDistance works as it dictates the Projection, distance and area units.
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Frank Fica
Sent: 18 April 2013 15:30
To: mapi...@googlegroups.com
Subject: [MI-L] Re: Unrecognized command: (.
Thanks Tom, I will give it a try. Weird ah?
--
Tom,
No specific reason, I just feel it helps organise and structure the code. His code looked like it could do with some structuring.
Regards
Adrian
|
Mouchel Limited (Mouchel) is registered in England and Wales with registered number 01686040 at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX. The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. No contracts may be concluded on behalf of Mouchel by means of email communications. Mouchel reserves the right to monitor and intercept emails sent and received on our network. |
--
Top spot Uffe!
Ok, it’s just it wasn’t what was in the original email
--