Re: Shape file entries - String to numerical?
Hey Linda,
Use the code snippet below to parse the "String" number objects to get their "int" numeric values. First, you must make sure that you are parsing "String" numerics not just text to int primitives, otherwise, it will do you no good to parse them. Second, you must try/catch for a NumberFormatException in case you are reading a String that is not number. If you know that your String numeric might exceed the range of an int, you might want to parse for "long" primitives instead:
Now here is what you should do for parsing int primitives:
try{
// this will be valid and won't throw up on you
int myInt0 = Integer.parseInt("1221");
// this is no good and will throw up on you 
int myInt1 = Integer.parseInt("23sdf");
}catch(NumberFormatException ex){
System.out.println(ex.getMessage());
}
For parsing String numeric that fit "long" primitives, you should use:
long myLong = Long.parseLong("87698798798723423");
Hope this solves your issue!
Best wishes,
Ahmed
hey guys,
I have another question. I do not know if it is really stuff for geotools.
Because the attributeName parameter from VectorToRaster.process() is
numerical, I have to change some elements in my shape file.
These are the facts:
I have a huge amount of colums with String entries. But in reality the
values are not Strings, but numeric entries. What now?
I have to evaluate all entries, if there is a number in it or not. And if
so, how to check on the elements? And then change it to some numeric
entries?!
Has anybody any idea how to do this with less effort?
<at> michael: did you check already my code from
http://n2.nabble.com/GridCoverage-Error-Points-of-LinearRing-do-not-form-a-closed-linestring-raster-attribute-matrix-tt4783764.html#a4783764.
I send it to you via email.
Thanks for your help
Linda
--
View this message in context: http://n2.nabble.com/Shape-file-entries-String-to-numerical-tp4833774p4833774.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev
_______________________________________________ Geotools-gt2-users mailing list Geotools-gt2-users@... https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
RSS Feed