We’re rewarding the question askers & reputations are being recalculated! Read more.

# Tag Info

8

Take a look at the section on slicing in the Python tutorial. You can grab a range of characters from a string using slicing syntax, e.g. D = int(x[1:2]). For seconds, try S = float(x[5:]). This will grab all the characters starting at index 5 to the end of the string, in the case that you have variable length values for seconds. The !FieldName! syntax is ...

6

If you are running QGIS 2.0.1, you can import the data as delimited text layer. It offers you to select DMS Coordinates, comma as decimal separator and EPSG:4326 as CRS. Once you have the data loaded, you can rightclick on the layer -> Save as and choose EPSG:32632 for the output file.

6

The following Python field calculation script should work for you (tested in ArcMap 10.0): Your expression should be: calc(!YOUR_FIELD_NAME_HERE!) And your code block should be: def calc(val): val = val.split('-') return u'%s\u00B0 %s\u2032 %s\u2033' % tuple(val) The \uXXXX characters are special unicode characters for °, ′, and ″ (thanks to ...

4

If you're working in Ubuntu, you could use this in a shell script: To get longitude like 81°5.8' (degree and minutes from code in d,m,s): tmp0=`echo 081054800 | cut -c2,3` tmp1=`echo 081054800 | cut -c5` tmp2=`echo 081054800 | cut -c6,7` tmp3=`echo "scale=2; \$tmp2/60" | bc -l` echo \$tmp0 \$tmp1 \$tmp3 | awk '{ print \$1"°"\$2\$3"'\''" }' which gives: 81°5.80' ...

4

Are the longitude and latitude values in separate fields? Because the Convert_Decimal function requires a single value. After trying this myself, I think you were trying to convert the DMS values to DD in-place. That is, in the same column. Instead, use the script in a new column, referring to the one you want to convert. See image below where I have a DMS ...

4

You're in the right direction. What you need to do is use the QGIS expression builder to concatenate a string with the degrees, minutes, seconds, and any symbols you want in between. This example calculates the \$x value, and will work for positive or negative values. (CASE WHEN \$x < 0 THEN '-' ELSE '' END) || floor (abs(\$x)) || '° ' || floor(((abs(\$x)) ...

4

Copy the coordinates into Excel. Split the coordinates into Degrees, Minutes and Seconds in separate cells. Take the degrees and add the (minutes/60) and add the (seconds/3600) DD+(MM/60)+(SS/3600) If the coordinate is in the south or west, multiply the final answer by -1 to make it a negative value. You can convert multiple coordinates in Excel this way,...

3

If you don't mind using Excel; you will get B1=45, C1=11, D1=35 with formula below. A1: 162695 B1: =FLOOR(A1/3600, 1) # D C1: =FLOOR((A1/3600 - B1)*60, 1) # M D1: =A1-B1*3600-C1*60 # S E1: =A1/3600 # Decimal Sorry I did not notice you were QGIS user. The above excel formula is basically applicable to Field ...

3

In QGIS 3.4, there is now a builtin expression to convert a coordinate into DMS or DM format. to_dms( \$x, 'x', 3) -> 62°31′7.951″ to_dms( \$x, 'x', 3, 'suffix') -> 62°31′7.951″E to_dm( \$x, 'x', 5, 'suffix') -> 62°31.13252′E

3

UTM always has metres as units. If you want degrees, change the project CRS to EPSG:4326 (WGS84) first. Then you can switch from decimal degrees to degrees-minutes-seconds as you did.

3

You're correct that this UoM is called decimal degrees, and partially correct that the value varies depending where you are on earth. One degree of latitude is always about the same width. One degree of longitude varies depending on what latitude you're at. The accepted answer to this question explains it well: Calculating longitude length in miles? The ...

3

These coordinates might be in New Brunswick Stereographic. Check your Easting coordinate, I think there is a missing digit. Using X=2451890.770 and Y=7438891.286 I arrive at N45° 56' 54.620", W67° 07' 13.896" in Dumfries. This online converter can help you convert your coordinates from UTM/MTM/Stereo to Latitude/Longitude

2

In integer DSM coordinates the best precision is a second so 1/60/60 or 0.000277778. So you need to truncate your results at 3 digits after the decimal so your results do agree. Update I went and looked at the code which seems as though you can specify the precision of the seconds variable through an option. hdms = ol.coordinate.toStringHDMS( coordinate,...

2

Obligatory XKCD reference: More detailed answer

2

When converting from DD⁰ MM' SS", you must remember that S latitudes will become negative and that W longitudes will become negative. Simply multiply the converted lat and/or lon by -1.

2

Writing functions that are supposed to return a certain thing (or things) and can actually return something else is bad practice and can cause unexpected errors to creep in. The standard way of doing this is to raise an exception with an informative message. # Handle Python 2.x. try:input = raw_input except NameError:pass def dms2dd(degrees, minutes, ...

2

I have a layer in OSGB coordinates (EPSG code 27700) and I can use to_dms(x(transform(\$geometry,'EPSG:4326','epsg:4326')), 'x', 3) to get a DMS representation of the point coordinates. For example, I can use this expression in the labelling engine: and my points get labelled with the DMS longitude, even though their coordinate system is still OSGB metres: ...

2

Outline solution: Get boundary data for all countries in the region (can be downloaded from gadm.org) Loop over all D/M/S on the earth, doing point-in-polygon tests over the boundary data from step 1 - this can be done using Python, R, Java or C or lots of other programming languages. Keep those D/M/S values that are inside the boundaries. How many points ...

2

Here's an implementation of the formula from Wikipedia, except that this will truncate fractional seconds because SQL only allows the modulo operator with ints. DECLARE @geom geometry; SET @geom = geometry::STGeomFromText('POINT(-83.255 32.567477)', 4326); SELECT CASE WHEN @geom.STX < 0 then '-' ELSE '' END + CAST(FLOOR(ABS(@geom.STX)) as varchar) +...

2

Thank you HDunn! I tweaked the code a little so it also displays North/E oriëntation and has no spaces in the coördinate line: For field (text string) X: (CASE WHEN \$x < 0 THEN '-' ELSE '' END) || floor (abs(\$x)) || '°' || floor(((abs(\$x)) - floor (abs(\$x))) * 60) ||'\'' || substr( (tostring((((abs(\$x)) - floor (abs(\$x))) * 60) - floor(((abs(\$x)) - ...

2

Yes, it is still widely used. All navigational devices and GIS software offers DMS format for displaying, saving and loading data. And many consumer oriented platforms use it as the main or only coordinate format. Beside practical things like the fact that a minute of latitude is one nautical mile. The main reason is that coordinates in DMS format are ...

1

Not only is it still relatively common, but other forms of representation are also possible. Many GNSS (usually GPS) systems will report DD MM.mmmm (degrees decimal minutes). There are also packed and unpacked forms of DMS, DDMMSS.ssss or DD MM SS.ssss. For computer processing, you're correct that just maintaining decimal degrees is easiest and only using ...

1

The <coordinates> are in longitude,latitude order. See https://developers.google.com/kml/documentation/kmlreference#syntax_151. So you wanted: <coordinates>0.03888889,51.45</coordinates> This is a pretty common mixup. Much of this stuff is done on a Cartesian plane, so think X-Y coordinates, and it'll make more sense.

1

Your coordinates are stored in decimal degrees, DMS is just one display method. You could modify the display using the field properties. Even if you force the precision of your field, but this will round to number stored in decimal degrees which will then be converted in DMS.

1

It worked I guess the problem was in the "degree" symbol which i replaced with "~" in the excel sheet and also in the vba code and bang !!! It worked !!! reference: https://www.youtube.com/watch?v=0QxxuSIFdFU

1

(Credit to @Russell at ISC for the use of the modulo operator.) We have a table in SQL Server with a column of geography data type, called [GeoCoor]. This is how we convert to degrees, minutes, and seconds: SELECT [GeoCoor].[Lat] as [DecimalLatitude], floor(ABS([GeoCoor].[Lat]))*(CASE WHEN [GeoCoor].[Lat] < 0 then -1 ELSE 1 END) as [LatDegrees], convert(...

1

I'm not sure what software you want to use or how you are handling that file, but since the Code is following XXX XX XX.XX for Degrees Minutes Seconds, respectively, you can convert manually: Decimal Degrees = Degrees + ((Minutes / 60) + (Seconds / 3600)) Decimal Degrees = 81 + ((05 / 60) + (48.00 / 3600)) = 81.096667 To get Degrees and Decimal Minutes -- ...

Only top voted, non community-wiki answers of a minimum length are eligible